Angular: IsEmpty filter
http://angularjs.org/
HTML
<script src="http://code.angularjs.org/angular-1.0.0rc8.js"></script>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<div ng-app="myApp">
<div ng-controller="MyCtrl">
<div>{{msg1 | isempty: 'Nothing'}}</div>
<div>{{msg2 | isempty: 'Nothing'}}</div>
<div>{{msg3 | isempty: 'Nothing'}}</div>
<div>{{msg4 | isempty: 'Nothing'}}</div>
<div>{{msg5 | isempty: 'Nothing'}}</div>
</div>
</div>
CSS
.message {
background-color: green;
color: white;
font-size: white;
height: 60px;
line-height: 60px;
}
JavaScript
var myApp = angular.module('myApp',[]);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
function MyCtrl($scope) {
$scope.msg1 = "hello, world";
$scope.msg2 = "";
$scope.msg3 = undefined;
$scope.msg4 = null;
$scope.msg5 = '';
}
myApp.filter('isempty', function() {
return function(input, replaceText) {
if(input) return input;
return replaceText;
}
});