Custom filter with parameters

Description

The following code shows how to create. Custom filter with parameters.

Example


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<script type='text/javascript'>
<!-- w w  w.  jav  a  2s.co m-->
angular.module('myApp', []).filter('exactString', function () {
    return function (string, term) {
        return ('' + string).indexOf(term) > -1;
    }
}).controller("myAppCtrl", function ($scope) {
    $scope.willMatch = "shipped";
    $scope.willNotMatch = "Partially Shipped";
});


</script>


</head>
<body ng-app="myApp">
  <div ng-controller="myAppCtrl">
    {{willMatch | exactString:'shipped'}}
    {{willNotMatch |exactString:'shipped'}}
</div>

</body>


</html>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities