filter
stateful filter
by Samar Pattanayak
HTML
<div ng-app='myApp'>
<div ng-controller="myController">
Enter the joining sep : <input type="text" ng-model="sep"/>
{{name | myFilter : sep }} </br>
Enter the joining sep : <input type="text" ng-model="state.sep"/>
{{name | myFilterStateful}}
</div>
</div>
JavaScript
var app=angular.module('myApp',[]);
app.controller("myController", function($scope,myValue){
$scope.name= "Samar";
$scope.sep='_';
$scope.state=myValue;
});
app.filter("myFilter", function(){
return function(input,num){
return input.split('').join(num) ;
};
});
app.filter("myFilterStateful", function(myValue){
function dec(input){
return input.split('').join(myValue.sep) ;
};
dec.$stateful= true;
return dec;
});
app.value("myValue", {sep : '%'});