In my Angular 2 project there is ngModel
and the radio button doesn't check it
<input type="radio" id="user" name="user" value="RETAIL" [(ngModel)]="myRadio" check>
But when I cut the ngModel
it check
<input type="radio" id="user" name="user" value="RETAIL check>
But I can't cut it because I need ngModel
, is there another way to check radio button on the load page with ngModel
?
If the value of the input element is a string literal, declare it using one of the two following forms:
<input type="radio" id="user" name="user" value="My value 1" [(ngModel)]="myRadio" />
<input type="radio" id="user" name="user" [value]="'My value 1'" [(ngModel)]="myRadio" />
If the value is not a string literal, use [value]
:
<input type="radio" id="user" name="user" [value]="MyValue1" [(ngModel)]="myRadio" />
To have the radio button selected by default, you should initialize myRadio
to the appropriate value:
For a string value:
public myRadio: string = "My value 1";
For another type of data:
public myRadio: MyDataType = MyValue1;
You see the code at work in this plunker.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With