filmov
tv
AngularJS Tutorial 16 - Custom filter in AngularJS

Показать описание
In this tutorial, we are going to learn about Custom Filter in angularJs
AngularJS provides us lot of built-in filters which we have already learned in previous videos
AngularJS gives a simple API to create Custom Filter. To create Custom Filter you need to create it the same way we have created controllers
return function(input, value1,value2){
var input;
return output;
}
});
In return function we must pass a single parameter which will be the data we will work on.
Once you grabbed the input you can format it according to your wish and at last you need to return the modified input as output.
Once filter is created you need to use it the same way , we have used built in filters.
You can apply filter in 2 ways either on collection like orderBy or limitTo filter or on simple type like string or number the way we have used uppercase or lowercase filter
You can also pass parameter to your custom filter
{{name : customFilter : para1 : para2 }}
these parameters will be copied after the first argument of return function of custom filter
Custom filters are quite easy to use in angular js. So at any time you feel that built-in filters are not enough for your requirement you are free to create your own custom filter.
AngularJS provides us lot of built-in filters which we have already learned in previous videos
AngularJS gives a simple API to create Custom Filter. To create Custom Filter you need to create it the same way we have created controllers
return function(input, value1,value2){
var input;
return output;
}
});
In return function we must pass a single parameter which will be the data we will work on.
Once you grabbed the input you can format it according to your wish and at last you need to return the modified input as output.
Once filter is created you need to use it the same way , we have used built in filters.
You can apply filter in 2 ways either on collection like orderBy or limitTo filter or on simple type like string or number the way we have used uppercase or lowercase filter
You can also pass parameter to your custom filter
{{name : customFilter : para1 : para2 }}
these parameters will be copied after the first argument of return function of custom filter
Custom filters are quite easy to use in angular js. So at any time you feel that built-in filters are not enough for your requirement you are free to create your own custom filter.
Комментарии