-
Notifications
You must be signed in to change notification settings - Fork 25.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(select): support objects as select values #7842
Conversation
1609c57
to
8b73e3b
Compare
@Input() | ||
set value(value: any) { | ||
if (this._select == null) return; | ||
this.id = this._select._addOption(this.id, value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you move it to the constructor?
Since id never changes, it is a bit confusing that you keep resetting it on every value change.
45eaaf9
to
6e017f6
Compare
@vsavkin All comments should be addressed. |
|
||
_getOptionId(value: any): string { | ||
for (let id of MapWrapper.keys(this._optionMap)) { | ||
if (this._optionMap.get(id) == value) return id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean to use ==
or ===
? Those two things are somewhat distinct in JS, and are very distinct in Dart.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did mean ==
to fix a Dart error, but thinking about it more, this is a bad solution. Obviously we don't want 6 to match "6". I'll fix it another way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use looseIdentical
fixture.detectChanges(); | ||
tick(); | ||
|
||
testComp.list[1] = {"name": "Buffalo"}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I can remove this line, and the test will still pass. Can you verify that the selected option is actually Buffalo?
187aea6
to
aa05492
Compare
@jeffbcross Fixed the Edge issues. Should be ready! |
Merging PR #7842 on behalf of @vsavkin to branch presubmit-vsavkin-pr-7842. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This fixes a current bug where objects set as option values and/or
[(ngModel)]
on select tags are converted to[object Object]
strings.For the following:
You might expect the select to display "Salt", but it displays "Pepper" because all option values are set to
[object Object]
. When selecting new options using the dropdown, theselected
property on the component class is set to[object Object]
.This PR allows you to write the above code and have the selection updated on both ends as expected.
No breaking changes.