I'm using angularjs 1.4.4
I'm trying to update the $locale dynamically and it is updating. When a filter gets run it uses the correct updated $locale to evaluate itself. Unfortunately old filters don't re-run themselves.
var englishMonths = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var frenchMonths = ["janvier", "f\u00e9vrier", "mars", "avril", "mai", "juin", "juillet", "ao\u00fbt", "septembre", "octobre", "novembre", "d\u00e9cembre"];
$scope.array = [];
$scope.currentDate = 'english';
$scope.addDate = function(){
$scope.array.push(new Date());
};
$scope.switchDate = function(){
var monthArray = englishMonths
if($scope.currentDate === 'english'){
monthArray = frenchMonths;
$scope.currentDate = 'french';
}
else{
$scope.currentDate = 'english';
}
$locale.DATETIME_FORMATS.MONTH.length = 0;
for(var x = 0; x < monthArray.length; x++){
$locale.DATETIME_FORMATS.MONTH.push(monthArray[x] + ($scope.currentDate === 'french' ? "FRENCH" : ''));
}
};
And in the dom:
<button data-ng-click="addDate()">Add Date</button>
<button data-ng-click="switchDate()">Toggle Language, current: {{ currentDate }}</button>
<hr></hr>
<div data-ng-repeat="date in array">
{{ date | date:'longDate' }}
</div>
If you add a date to the array it will evaluate at the current language. If you change the language the old dates won't re-evaluate.
You can see this in the fiddle I've made: http://jsfiddle.net/wf8ojqjg/
So I need a way for the $locale to update, which really boils down to forcing all filters to recalculate.