angularjs filter example
by anazimok
HTML
<div ng-app="myApp" ng-controller="MyCtrl">
<input type="text" ng-model="message">
<div>{{ message | greet }}</div>
</div>
CSS
</style> <!-- Ugly Hack due to jsFiddle issue: http://goo.gl/BUfGZ --> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script> <style> .ng-invalid {
border: 1px solid red;
}
JavaScript
// declare a module
var myAppModule = angular.module('myApp', []);
myAppModule.controller('MyCtrl', function ($scope) {
$scope.message = "Alex";
});
// configure the module.
// in this example we will create a greeting filter
myAppModule.filter('greet', function () {
return function (name) {
return 'Hello, ' + name + '!';
};
});