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

Using NgModel and NgControl on Radio button causes TypeError: _this._state is undefined #9153

Closed
divyakumarjain opened this Issue Jun 11, 2016 · 6 comments

Comments

Projects
None yet
2 participants
@divyakumarjain
Copy link

divyakumarjain commented Jun 11, 2016

  • I'm submitting a ...
  • bug report
  • feature request
  • support request => Please do not submit support request here, see note at the top of this template.

Current behavior
Using NgModel and NgControl on Radio button causes following issue in console.

TypeError: _this._state is undefined in Firefox
TypeError: Cannot read property 'value' of undefined in chrome

Expected/desired behavior
Toggling of Radio button should work.

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via
    http://plnkr.co/edit/1G2mPd
  • What is the expected behavior?
    Toggling of Radio button should work.
  • Angular version: 2.0.0-rc.1
  • Browser: [all]
  • Language: [all]
@divyakumarjain

This comment has been minimized.

Copy link

divyakumarjain commented Jun 11, 2016

Have updated the plnkr to include a text input which works but radio button does not.

http://plnkr.co/edit/1G2mPd?p=preview

@divyakumarjain

This comment has been minimized.

Copy link

divyakumarjain commented Jun 11, 2016

Following is the smallest plnkr where i can reproduce the issue.

http://plnkr.co/edit/p4vyND

@zoechi

This comment has been minimized.

Copy link
Contributor

zoechi commented Jun 11, 2016

That's because you bind ngModel to a property that doesn't exist. For <input type="radio"> it needs to hold a RadioButtonState otherwise it throws when it accesses the value theModel.value.

If you want a default value, then assign it to the model ([(ngModel)]="model"). As far as I know [(ngModel)]="..." and `[value]="..." together usually don't produce the result you want.

@Output() is only for EventEmitter, not for arbitrary properties.

Either

/* @Output() */ model = {"details": {"title": "mr"}, "name": "Developer"};

or

@Output() modelChange = new EventEmitter(); /* model = {"details": {"title": "mr"}, "name": "Developer"}; */

GitHub issues are for bug reports and feature requests.
For support questions please use other channels like the ones listed in CONTRIBUTING - Got a Question or Problem?

@divyakumarjain

This comment has been minimized.

Copy link

divyakumarjain commented Jun 11, 2016

@divyakumarjain

This comment has been minimized.

Copy link

divyakumarjain commented Jun 11, 2016

Each <Input type="radio should have its own model of type RadioButtonState. Binding value to model is not supported

@zoechi

This comment has been minimized.

Copy link
Contributor

zoechi commented Jun 11, 2016

Plunker that at least doesn't produce exceptions http://plnkr.co/edit/1apvt8?p=preview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment