How to configure a verified attribute with an intermediate option?

I have a set of switches for the day, month, and year.

<label>
   <input type="radio" ng-model="IsDays" name="timeunit" > Period in days
   <input type="radio" ng-model="IsMonths" ng-checked="true" name="timeunit"> Period in months
   <input type="radio" ng-model="IsYears" name="timeunit" > Period in years
</label>


I read that, despite the fact that the highlighted attribute was included in the intermediate option, the last button in the group will be marked if the radio buttons have the same name .

I tried this with both verified and ng-checked = "true" scripts.

Is there an easy way to override this behavior and let it default to checking the intermediate option (month)?

UPDATE . Solved my own question. See answer below.

+4
source share
2 answers

:

, .

check = "checked", . .

<label>
 <input type="radio" ng-model="IsDays" name="timeunit" > Period in days
 <input type="radio" ng-model="IsMonths" checked="checked" name="timeunit"> Period in months
 <input type="radio" ng-model="IsYears" name="timeunit" > Period in years

:)

: cookie . AngularJS, .

        <label>
            <input type="radio" ng-model="timeunit" value="days">
            Period in days
        </label><br />
        <label>
            <input type="radio" ng-model="timeunit" value="months">
            Period in months
        </label><br />
        <label>
            <input type="radio" ng-model="timeunit" value="years">
            Period in years
        </label><br />

, , ng- , .

, js

 function ($scope) {

    $scope.timeunit = "months"; //Default set to months

  //Other code
 }
+1

, ngInit :

<input type="radio" ng-model="IsMonths" ng-init="checked=true" name="timeunit"> Period in months
0

Source: https://habr.com/ru/post/1660370/


All Articles