[CompareWith] issue
See original GitHub issueExpected behaviour
Hi guys, I was trying to use compareWith parameter in your plugin, but it doesn’t work. Here is one of issue inside my project: I want to take parameters from ‘ActivatedRoute’ and pass them as default values into ng-select controls, but I can’t do this, because data for this dropdown is using numeric type whereas parameters from queryParams are string. Yes, of course I can change type inside control manually but it’ll take a lot of time and string of code. It would be great to have a possibility to configure this feature globally. Thanks
Actual behaviour
According to README we have it, but how does it works? I was trying to use it through passing function inside ng-select like this
<form [formGroup]="form">
<label>Your first ng-select</label>
<ng-select formControlName="car_id" [items]="cars"
bindLabel="name"
bindValue="id"
[compareWith]="compareFn"
placeholder="Select some car">
</ng-select>
</form>
public compareFn(a, b): boolean {
return a == b;
}
no results https://stackblitz.com/edit/ng-select-example-rhenac?embed=1&file=app/app.component.ts
More Info
ng-select version: [2.1.0]
browser: [Google Chrome 66.0.3359.181]
reproducible in demo page: [NO]
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Here is PR https://github.com/ng-select/ng-select/pull/586 to allow use compareWith with bindValue
@varnastadeus hello! I faced with that problem too, I used all the rest autocomplete components in angular2-6 and I think your implementation is one of the best. BUT this behaviour is really weird - because if you will not approve this change, all the developers who faced this problem too will be forced to write 20+ LOC for each widget instance to avoid it. If you will approve this change it will not brake anything (btw: you don’t have any notice that [compareWith] isn’t works with [bindValue]), so if somebody needs this function they will just use it, who’s not - will not use.
PS: Thank you a lot for your really good component!