Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boolean radio-buttons in Angular 2+ Forms

Tags:

forms

angular

I want to be able to have a radio button group of two items in order to have a yes-no toggle.

The following snippet works, but has a "true"/"false" string value as item.value

<input type="radio" [formControl]="item" name="{{item.id}}" value=true>
<input type="radio" [formControl]="item" name="{{item.id}}" value=false>

How do I get an boolean value in item.value?

I tried the following without success:

<input type="radio" [formControl]="item" name="{{item.id}}" [ngValue]=true>
<input type="radio" [formControl]="item" name="{{item.id}}" [ngValue]=false>

It throws

Can't bind to 'ngValue' since it isn't a known native property

I am using Angular 2 RC4 with Angular Forms 0.2.0.

like image 273
mvermand Avatar asked Jul 05 '16 12:07

mvermand


1 Answers

I think this is what you want:

<input type="radio" [formControl]="item" name="{{item.id}}" [value]=true>
<input type="radio" [formControl]="item" name="{{item.id}}" [value]=false>
like image 139
Günter Zöchbauer Avatar answered Oct 23 '22 19:10

Günter Zöchbauer