Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-model preventing checked="checked" to select radio button by default

When I use checked="checked" ng-model prevents the radio button from being selected by default. Does anyone know what could be causing this?

<input type="radio" name="unitMiles" checked="checked" id="unitMiles" value="Miles" ng-model="unit" ng-change='nextActivityStep(3)'>
like image 211
Horace Heaven Avatar asked Sep 25 '13 19:09

Horace Heaven


People also ask

How do I make radio buttons not checked by default?

You can check a radio button by default by adding the checked HTML attribute to the <input> element. You can disable a radio button by adding the disabled HTML attribute to both the <label> and the <input> .

How to make radio button checked in AngularJS?

AngularJS ng-checked Directive The ng-checked directive sets the checked attribute of a checkbox or a radiobutton. The checkbox, or radiobutton, will be checked if the expression inside the ng-checked attribute returns true. The ng-checked directive is necessary to be able to shift the value between true and false .

What is NG model?

The ngModel directive is a directive that is used to bind the values of the HTML controls (input, select, and textarea) or any custom form controls, and stores the required user value in a variable and we can use that variable whenever we require that value. It also is used during form validations.


1 Answers

You should be using the ngChecked directive that comes with Angular.

Doc: http://docs.angularjs.org/api/ng.directive:ngChecked

like image 144
tymeJV Avatar answered Sep 28 '22 00:09

tymeJV