md-select: add compareWith function
See original GitHub issueCurrently, md-select values are compared by object reference. This is a bit inflexible. We want to allow people to compare options by a custom comparator in case they only care about the object’s ID or some other property.
Example markup:
<md-select placeholder="Food" [(ngModel)]="food" [compareWith]="compareById">
<md-option *ngFor="let food of foods" [value]="food"> {{ food.name }} </md-option>
</md-select>
compareById(obj1, obj2) {
return obj1.id === obj2.id;
}
This will be parallel to functionality being added to native selects in core.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:30
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Using compareWith in Angular Material 2 multiple-select ...
The compareWith just literally compares objects by some given values and the checkboxes get selected, if it returns true . Once done, any...
Read more >Select | Angular Material
(Additional information about using a custom compareWith function can be found in the Angular forms documentation). Select in a form. link code
Read more >Use compareWith function from Angular Material mat-select ...
I'm trying to edit some member's firebase data with a mat-select component composed of different types. I'm not sure with my structure of...
Read more >Angular Material options - Hardcoded value working ...
You have to put the .setValue function inside the subscription. this.listApiService.getListOfEventTypes().subscribe(data => { (data as Array<any>).
Read more >Using a compareWith Function in Angular Material - YouTube
This video will show you how to use a compareWith function in Angular Material. Check out the source code from this sample at ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sounds good, regarding commit 😃 When will be the next release?
Desperately need this 👍