angular.js - Radio button in ng-repeat selects first item by default
PHP中文网
PHP中文网 2017-05-15 17:10:19
0
3
732

Several radio button boxes generated by ng-repeat, how to select the first one

by default?
<p class="radio"ng-repeat="item in imgList">
  <label>
    <input type="radio" name="opt"
           ng-value="item.id"
           ng-click="seleMon($event)"
           ng-model="selectedMonth">
    <span>{{item.mon}}</span>
  </label>
</p>

js

$scope.imgList = [
      {
        'mon':'1月',
        'id':'1',
      },
      {
        'mon':'2月',
        'id':'2',
      },
      {
        'mon':'3月',
        'id':'3',
      },
      {
        'mon':'4月',
        'id':'4',
      }
 ]
$scope.selectedMonth = $scope.imgList[0];

Why can’t I select the first item by default? How should I change it?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
过去多啦不再A梦
**$scope.selectedMonth = $scope.imgList[0].id;**

ng-valueng-model要能匹配,你当前的写法,ng-model是对象,ng-value is a string. Just add the id.

曾经蜡笔没有小新

cheked={{$index}}==1?true:false;

曾经蜡笔没有小新

selectedMonth = 1;

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template