Reputation: 11
Ng-select (https://github.com/ng-select/ng-select) is not updating values when pipe transform is called dynamically, eg.when service for translating option values is called.
I tried to use both - ng-option way and ng-template way.
Ng-option- search works, but values not updating after language change. Ng-template - values updating after change, but search is not working.
Example: https://stackblitz.com/edit/ng-select-angular6-b5ru39
Expected result would be that options auto update or that search with ng-template works fine when pipe transform is called.
Upvotes: 1
Views: 1045
Reputation: 312
Your language service should expose the currentLanguage as an Observable. Once it is an Observable, you can subscribe to it in the view with the async pipe. Using that, the ChangeDetection of Angular kicks in to call the pipe again.
You can even let your pipe be pure (which is the default), because it is called again by Angular with the new language code.
I've worked it out for you in this fork of your Stackblitz.
Also, please take in mind there are plenty of good libraries for translation (TransLoco, ngx-translate) but you still have to use your solution if the data itself it dynamically retrieved from a server.
Upvotes: 1