Skip to content
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
1 of 3 tasks
divyakumarjain opened this issue Jun 11, 2016 · 7 comments
Closed
1 of 3 tasks

Comments

@divyakumarjain
Copy link

  • 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
Copy link
Author

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

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

@divyakumarjain
Copy link
Author

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

http://plnkr.co/edit/p4vyND

@zoechi
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
Copy link
Author

@zoechi plunk http://plnkr.co/edit/p4vyND has issue so please look at http://plnkr.co/edit/1G2mPd

@divyakumarjain
Copy link
Author

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

@zoechi
Copy link
Contributor

zoechi commented Jun 11, 2016

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

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants