Is there a way to update the filter in the code below?
.controller('MainCtrl', ["$rootScope", "$scope", function($rootScope, $scope) {
$rootScope.number = 1;
$scope.text = "foo|baz|bar"
}]).filter("MyFormat", ["$rootScope", function($rootScope){
return function(str){
return str.split("|")[$rootScope.number]
}
}])
<button ng-click="$root.number = 0">0</button><!--foo-->
<button ng-click="$root.number = 1">1</button><!--baz-->
<button ng-click="$root.number = 2">2</button><!--bar-->
<pre>{{text | MyFormat}}</pre>
Check out this Plunker example.