Can a filter be dependent on a lazy-loaded value?
In my scenario, a language pack is loaded asynchronously and the filter should only reflect the loaded values once they are available.
// setting up the i18n filter
app.filter('i18n', ['localizedTexts', function(localizedTexts) {
return function(localeKey) {
console.log(localeKey, localizedTexts) // will show null for the second argument initially
return localizedTexts && localizedTexts[localeKey];
};
}]);
// setting up the default value
app.value('localizedTexts', null);
// loading values
app.run(['$http', function($http) {
$http.get('values.json').success(function(response) {
// updating the value -- does not invalidate the filter or the view
app.value('localizedTexts', response);
});
}]);
I have provided a Plunker demo as well: http://plnkr.co/edit/THTD3UiYgegusCl54Qhp?p=preview
What do you think?