How to redraw angular filters

Is there a way to reprocess AngularJS filters? I am trying to use an angular currency filter that displays a currency symbol based on a loaded language file. I need to redisplay the filters when I programmatically download the corresponding language file.

+4
source share
3 answers

From Angular 1.3, filters are idle, which means that filters will only be updated when their input is changed.

If you want to update your filter, you need to make your filters $ stateful .

app.filter('translate', translate);

translate.$inject = ['$rootScope'];

function translate($rootScope){

    filter.$stateful = true;

    return filter;

    function filter(str) {
        return i18n[$rootScope.currentLang][str];
    };
}

Filters will be executed on every $ digest, but this is not practical with perfm.

+4
source

. $watch. $watch, . , , $scope. $Apply(), , .

0

/ :

, .

, , , - , . , , .

I recently ran into this problem figuring out how to dynamically re-display output.js in a locale change event. This is my filter function:

function FromNowFilter($moment) {
    return function (value, langKey, omitSuffix) {
        //langKey parameter is only used for triggering an update when language is changed
        return $moment(value).fromNow(omitSuffix);
    }
}
0
source

All Articles