admin管理员组

文章数量:1426203

Filters, I want to select first one radio button.

Restorent1 ✔ | restorent 2 | restorent3 | restorent4

<div ng-repeat="restorent_type in restaurant_types" style="margin:5px;" class="col col-offset-10">
    <label class="item item-radio radio-label {{restorent_type.RESCOD}}">
        <input type="radio" name="group" ng-model="restorent.types" value="{{restorent_type.RESCOD}}" ng-click="filters.RESCOD = restorent_type.RESCOD">
        <div class="item-content">
            {{restorent_type.RESCOD}}
        </div>
        <i class="radio-icon ion-checkmark"></i>
    </label>
</div>

Filters, I want to select first one radio button.

Restorent1 ✔ | restorent 2 | restorent3 | restorent4

<div ng-repeat="restorent_type in restaurant_types" style="margin:5px;" class="col col-offset-10">
    <label class="item item-radio radio-label {{restorent_type.RESCOD}}">
        <input type="radio" name="group" ng-model="restorent.types" value="{{restorent_type.RESCOD}}" ng-click="filters.RESCOD = restorent_type.RESCOD">
        <div class="item-content">
            {{restorent_type.RESCOD}}
        </div>
        <i class="radio-icon ion-checkmark"></i>
    </label>
</div>
Share Improve this question asked Jun 20, 2015 at 7:01 Uttam PanaraUttam Panara 5492 gold badges10 silver badges28 bronze badges 1
  • and if i want to generate click event of it then it is possible? – Uttam Panara Commented Jun 20, 2015 at 7:19
Add a ment  | 

4 Answers 4

Reset to default 3

Use ng-checked

If we put an Angular interpolation expression into such an attribute then the binding information would be lost when the browser removes the attribute. The ngChecked directive solves this problem for the checked attribute. This plementary directive is not removed by the browser and so provides a permanent reliable place to store the binding information.

<input type="radio" name="group" ng-model="restorent.types" value="{{restorent_type.RESCOD}}" ng-checked="$index === 1 ? true : false" ng-click="filters.RESCOD = restorent_type.RESCOD">

Or Use

ng-checked="$first"

you can use $first also

<div ng-repeat="restorent_type in restaurant_types" style="margin:5px;" class="col col-offset-10">
    <label class="item item-radio radio-label {{restorent_type.RESCOD}}">
        <input type="radio" name="group" ng-model="restorent.types" value="{{restorent_type.RESCOD}}" ng-click="filters.RESCOD = restorent_type.RESCOD" ng-checked="$first">       
        <div class="item-content">
            {{restorent_type.RESCOD}}
        </div>
        <i class="radio-icon ion-checkmark"></i>
    </label>
</div>

It's easy, you can do this in your controller:

restaurant_types[0].types = true;

check first restaurant_types[0].types to true

Good Quation Try This Code

angular.module "myApp", []

angular.module("myApp").controller "myCtrl", ($scope) ->

  $scope.keywords = [{name: "kw1", checked: false}, {name: "kw2", checked: true}]

本文标签: javascriptHow to check first checkbox from ngrepeat loop in angular jsStack Overflow