When I use both compareWith and bindValue I would expect that compareWith will still used for comparing.
Run this with console opened.
https://stackblitz.com/edit/angular-d1cvpv?file=src/app/hello.component.ts
Nothing shows up in console. But if you remove bindValue the "test" from compareFn should appear in console two times.
Because my initial ngModel is always a string but values in items might be strings or numbers. I want to convert ngModel and values to sting before comparing them in compareWith
ng-select version: 1.4.1
browser: all
reproducible in demo page: NO
@tomasz-nowakowski-stx I am not sure if it makes sense to use compareWith with bindValue. Here is why:
When you use let say bindValue="id", you already tell that your value should match id property of items list so having compareWith seems redundant.
It will produce inconsistent results.
items = [{ id: 7, name: 'Vilnius' }]
Eg.: if you have your value as string '7', initial NgModel will stay as string, but if you select it from the dropdown, NgModel would switch to number.
Having this in mind, solution for your case would be casting string to number before setting the model.
@varnastadeus The problem is that I never know if values from API are strings or numbers (don't blame me 馃槂). And inconsistency you mentioned is fine for me in this case.
But I see your arguments and that it might be confusing for some people in the future. But compareWith working only in some cases might me confusing also as it is was for me :)
Hi guys! I'm the one of developers who, as @varnastadeus said, faced with the same problem. ng-select is really good plugin, but if someone wants to embed it into big project it leads to big problems because of strict comparison('==='). I don't ask you guys to change just compareWith behavior, but maybe you can help by the other way!? As a result for now you're losing a big percent of developers that want to use your product because as I said implementing ng-select into big project takes a lot of time and necessity to write some additional middleware because of ng-select that's not good in my opinion
Most helpful comment
https://github.com/ng-select/ng-select/pull/586