简体   繁体   中英

Why isn't my angular radio button marked as selected ( i have to click twice)

<li ng-repeat="flagVm in flagVms track by $id(flagVm)">
    <label for="alternative{{$index}}" ng-click="alternativeClicked()">
        <input ng-model="$parent.alternative" value="{{ flagVm.id }}" type="radio" name="alternative{{$index}}" /> 
        <span class="num-times-flagged">(Flagged {{ flagVm.count }} {{ flagVm.count > 1 ? 'times' : 'time' }}) </span>
        Inference Id: 
        <span class="highlighted-id">{{ flagVm.duplicateId }}</span>
    </label>
</li>

and

$scope.alternativeClicked = function (id) 
{
    //once iterating will probably be the actual flag obj
    $scope.alternativeFound = 'yes';
};

I think using ng-click with radio is a bad practice.

The better way is to use ng-change or $watch value change

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM