Just starting out so please be kind!!
Encountering an issue with Angular 1.3 while using a Stateful Filter within a controller.
In brief, when utilizing the $filter('custom')(data) method instead of the {{ data | custom }} method - and the custom filter gets updated (e.g., due to a service update), only the inline ( {{ }} ) filter reflects the changes on the view.
Check out the Plunkr here: http://plnkr.co/edit/nukioL3ORnl9KDPHmNoY?p=preview
(function(angular) {
'use strict';
angular.module('myStatefulFilterApp', [])
.filter('decorate', ['decoration',
function(decoration) {
function decorateFilter(input) {
return decoration.symbol + input + decoration.symbol;
}
decorateFilter.$stateful = true;
return decorateFilter;
}
])
.controller('MyController', function($filter, $scope, decoration) {
$scope.greeting = 'hello';
// This will update
$scope.decoration = decoration;
// This won't
$scope.code = $filter('decorate')($scope.greeting);
})
.value('decoration', {
symbol: '*'
});
})(window.angular);
I've experimented with different solutions for this issue, including event listeners, but it seems that none of those will solve the problem.
This problem initially arose from using the date filter and the locale plugin that dynamically updates the locale, resulting in the filter not updating when the locale changes.
Any suggestions on how to make the code-based filter monitor changes (possibly using a $watch task) are greatly appreciated.
Thanks in advance.
- Adam