I have two questions.
how to pass param to a filter function.
say for example:
item in masterData|filter1:masterdata|filter2:outputFromfilter1, myparam | filter3:outputFromfilter2, myparam1,myparam2
how to access the controller $scope
inside the filter function.
animateAppModule.filter( 'distinct' , function(){
return function(masterdata){
//HOW TO ACCESS THE $scope HERE
}
})
Here is a fiddle. Pls. look in to the firebug console, to see that the parameters passed to the filter is undefined
.
Using the filter filter you won't be able to pass in a parameter but there are at least two things you can do. 1) Set the data you want to filter by in a scope variable and reference that in your filter function like this fiddle. 2) Create a new filter that takes in a parameter like this fiddle.
7) Which of the following syntax is correct for applying multiple filters in AngularJS? Answer: A is the correct option. The syntax of applying multiple filters in AngularJS can be written as: {{ expression | filter1 | filter2 | ... }}
The “filter” Filter in AngularJS is used to filter the array and object elements and return the filtered items. In other words, this filter selects a subset (a smaller array containing elements that meet the filter criteria) of an array from the original array.
Introduction to AngularJS Custom Filter. In AngularJS filters are used to modify or update the data before rendering the data on view or UI. Filters are clubbed in expression or directives using pipe (|) symbol.
You can give parameters separated by :
into the filter.
For example,
{{ array | myfilter:a:b:c }}
In your filter definition,
angular.module('app', []).
filter('myfilter', function() {
return function(in, param1, param2, param3) {
// do something
};
});
Not sure why you need to access $scope
.
Can you simply feed whatever needed information via param as your Q1?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With