MdSelect hangs browser if FormControl does not exist
See original GitHub issueBug, feature request, or proposal:
Bug
What is the expected behavior?
No values populated in the select control, or exception thrown
What is the current behavior?
Hangs the browser (Chrome and Safari at least, Edge/FF not tested)
What are the steps to reproduce?
set formControlName
to the name of a control that doesn’t exist on the formGroup, i.e. if you accidentally left out a form control. If you’re using form.patchValue()
to set the form controls it seems to prevent this issue if the control name is in the object passed to patchValue(), which might make the bug appear more random.
i.e.
<md-select placeholder="Country" formControlName="Country">
<md-option *ngFor="let country of countries" [value]="country.IsoCode">
{{country.Name}}
</md-option>
</md-select>
where “Country” is not the name of a FormControl on the current FormGroup.
Providing a Plunker (or similar) is the best way to get the team to see your issue. Plunker template: http://plnkr.co/edit/o077B6uEiiIgkC0S06dd
What is the use-case or motivation for changing an existing behavior?
Which versions of Angular, Material, OS, browsers are affected?
Is there anything else we should know?
Seems to be an infinite loop running here:
/**
* Sets the select's value. Part of the ControlValueAccessor interface
* required to integrate with Angular's core forms API.
*
* @param value New value to be written to the model.
*/
MdSelect.prototype.writeValue = function (value) {
var _this = this;
if (!this.options) {
// In reactive forms, writeValue() will be called synchronously before
// the select's child options have been created. It's necessary to call
// writeValue() again after the options have been created to ensure any
// initial view value is set.
Promise.resolve(null).then(function () { return _this.writeValue(value); });
return;
}
this._setSelectionByValue(value);
};
Issue Analytics
- State:
- Created 7 years ago
- Comments:14 (3 by maintainers)
Top Results From Across the Web
Error in Nested Reactive Forms - Property 'controls' does not ...
Have a type conversion to FormArray as it's expecting that. getControls() { return (this.productsForm.controls.brands as FormArray).controls ...
Read more >How to Validate Angular Reactive Forms - freeCodeCamp
We will get the FormControl for these two fields and then match the values in them. If the values do not match, we...
Read more >Angular reactive form validation with FormBuilder
FormControl is a class in Angular that tracks the value and validation status of an individual form control. One of the three essential ......
Read more >Angular Forms Guide: Template Driven and Reactive Forms
This post is an in-depth comparison between the two different alternatives for building forms in Angular - Template Driven Forms and ...
Read more >FormArray - Angular
Tracks the value and validity state of an array of FormControl , FormGroup or FormArray instances. ... Further information is available in the...
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
Hi guys,
I got a similar issue when I try to render multiple md-options with an array of objects. The browser hangs when angular is trying to render the view.
This doesn’t work:
But this does:
Any ideas?
Thanks
Could this be related to the rendering of options somehow?
By attaching the VS Code debugger and manually breaking, and then stepping through a couple of times, I was able to determine the browser was hanging because of an infinite loop, repeatedly hitting and satisfying the
if (!this.options)
condition quoted above, which just seems to call writeValue recursively until there’s options?