Passing multiple arguments in angularjs filter
A demo code on how to pass multiple parameters in angular js filter
by Parth
HTML
<body ng-app="filterApp">
<div ng-controller="filterCtrl">
Dynamic Data :- <span ng-bind="'TEST' | testFilter: { 'be': val, 'se': value2 }"></span>
<br>
Static Data :- <span ng-bind="'TEST' | testFilter"></span>
</div>
</body>
<!-- Partha Roy -->
JavaScript
var app = angular.module('filterApp',[]);
app.value('test_obj', {'TEST' : 'test {{be}} check {{se}}'});
app.filter('testFilter', [ 'test_obj', function(test_obj) {
function test_filter_function(key, dynamic_data) {
if(dynamic_data){
var temp = test_obj[key];
for(var property in dynamic_data){
temp = temp.replace('{{'+property+'}}', dynamic_data[property]);
}
return temp;
}
else{
return test_obj[key] || key;
}
}
test_filter_function.$stateful = true;
return test_filter_function;
}]);
app.controller('filterCtrl',function($scope){
$scope.value1 = ['Sidd'];
$scope.value2 = 'two';
});