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.

MdSelect hangs browser if FormControl does not exist

See original GitHub issue

Bug, 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:closed
  • Created 7 years ago
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
aufdenpunktcommented, Jan 25, 2017

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: screen shot 2017-01-25 at 23 50 23 screen shot 2017-01-25 at 23 50 49

But this does: screen shot 2017-01-25 at 23 52 13

Any ideas?

Thanks

1reaction
mrlundcommented, Jan 26, 2017

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?

Read more comments on GitHub >

github_iconTop 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 >

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