The built-in filters cover many common use cases. but there are scenarios where we may have to create our own filters and use it as per the requirement which cannot be achieved using inbuilt filters .
Creating Custom filter to find StringLength
<body>
<div>
<form>
<input type = "text" ng-model="acc"/>
<div>
String Length is : {{acc|stringLength}}
</div>
</form>
</div>
<script>
angular.module('myapp', [])
.filter('stringLength',function()
{
return function(input){
return input.length;
}
}
);
</script>
</body>
Creating Custom filter to find StringLength
<body>
<div>
<form>
<input type = "text" ng-model="acc"/>
<div>
String Length is : {{acc|stringLength}}
</div>
</form>
</div>
<script>
angular.module('myapp', [])
.filter('stringLength',function()
{
return function(input){
return input.length;
}
}
);
</script>
</body>
No comments:
Post a Comment