is there a way to update filter with async data

二次信任 提交于 2020-01-04 13:51:08

问题


I had build the next angular filter:

App.filter('cur2symbol', ['CurrenciesService', function (CurrenciesService) {
        return function (input, iso) {
            input = input || '';
            iso = iso || 'ILS';
            var symbol= CurrenciesService.getCurrencySymbolByIso(iso);

            return symbol+input;
        };
    }])

the meaning of this filter is to get currency iso code and convert is to symbol for examle:
the next code {{200|cur2symbol:"ILS"}} will output ₪200.

My problem is that the CurrenciesService service is Async, so the filter is not working correctly. only filtering After the the service load are getting the symbol.

I thought about the next solutions:
1. Instead of using filter, using directive and making the symbol a Model, so it will update when the data is loaded. the problem is it will create too much bindings, I am using the currency symbol in many places!.
2. finding a way to run the filter again after the service has loaded (I don't know if it's even possible)

I will be glad for any ideas solution

来源:https://stackoverflow.com/questions/28841486/is-there-a-way-to-update-filter-with-async-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!