问题
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