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

Input of radio does not work well. #7374

Closed
ibufu opened this issue Mar 2, 2016 · 7 comments
Closed

Input of radio does not work well. #7374

ibufu opened this issue Mar 2, 2016 · 7 comments

Comments

@ibufu
Copy link

ibufu commented Mar 2, 2016

<input type="radio" value="a" [(ngModel)]="radioValue">
<input type="radio" value="b" [(ngModel)]="radioValue">
{{radioValue | json}}
radioValue = 'a';

The value of radioValue will be 'a' or 'b' in angular1.
In angular2, tow radios will be unchecked at the initialization and the value of radioValue will be { "checked": true } , when I click one of them.

@zoechi
Copy link
Contributor

zoechi commented Mar 2, 2016

dup of #3104? (maybe also #5133)

@ibufu
Copy link
Author

ibufu commented Mar 3, 2016

@zoechi
I think it is different with #3104 and #5133. There is plunker.

@byavv
Copy link

byavv commented Mar 3, 2016

+1, Seemed like a bug. It've never hapened in prev beta versions. Being in a form, radioinput's value represents as RadioButtonState ({ "checked": true } as @ibufu noted) If you need to solve it right now, try something like this:

<input type="radio"
         value="a" 
         #a
         ngControl="gender"
         (click)="radioValue = a.value" >   
...
<input type="radio"
         #b
         value="b" 
         ngControl="gender" 
         (click)="radioValue = b.value" >

Works for me.

@ibufu
Copy link
Author

ibufu commented Mar 3, 2016

@byavv
The initial state of radioValue could get from server, so we may should bind it to radio. But ngModel does not work well.

@byavv
Copy link

byavv commented Mar 3, 2016

@ibufu, it shouldn't be designed this way, but just for a smile)

 <label class="radio-inline">
                        <input type="radio"
                        value="male" 
                        #male
                        [checked]="child.gender === 'male'"
                        (click)="child.gender = male.value"
                        name="gender">Male</label>                   

                    <label class="radio-inline">
                        <input type="radio"
                        #female
                        value="female"
                        [checked]="child.gender === 'female'" 
                        (click)="child.gender = female.value" 
                        name="gender">Female</label> 

Will work in your case

@kara
Copy link
Contributor

kara commented May 23, 2016

This looks like the same issue as #7642. Closing in favor of the other issue, so we can track it in one place :) Thanks for reporting!

@kara kara closed this as completed May 23, 2016
@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

4 participants