question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[CompareWith] issue

See original GitHub issue

Expected 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? bs44chd 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:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
anjmaocommented, May 29, 2018

Here is PR https://github.com/ng-select/ng-select/pull/586 to allow use compareWith with bindValue

1reaction
BioSincommented, May 29, 2018

@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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

compareWith not triggered when list of items is updated #1587
When the model already has a selected item and the data is already available or fast enough there are no issues. But when...
Read more >
Using compareWith in Angular Material 2 multiple-select ...
Recently I needed to implement setting some objects as selected per default in the mat-select multiple-choice input options. The user should see the...
Read more >
PDF comparison issue in CompareWith method.Comparison ...
I face a problem when testing the compare functions on pdf documents that we produce with our software. The pdfs have about 17...
Read more >
select - Angular 7 can compareWith be used with a modal?
The compareWith function works just fine, but once you exit out of the modal and re-enter(without refreshing the page), the second parameter in ......
Read more >
Diabetes Prevention Program Sites Compared With ... - CDC
Diabetes Prevention Program Sites Compared With Diabetes Prevalence and Ratio of Primary Care Physicians in Texas. Prev Chronic Dis 2019;16: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found