angularJS select

ng-options指令

  在angularJS中创建select下拉是使用ng-options创建下拉项

ng-options="val as label for element in array"  //设置option的value值为val

ng-options="lable for element in array"  //不设置option的value值,默认为element对象

ng-options="(label)group by group for element in array"  //不设置option的value值,默认为element对象

 

<div ng-controller="selectCtrl">
    <select ng-model="menu" ng-options="m.id as m.name for m in selectArray"></select>
    {{menu}}
</div>
myApp.controller('selectCtrl',function($scope){
    $scope.selectArray=[
        {id:'1', name:'apple'},
        {id:'2', name:'pear'}
    ]
})

posted @ 2016-04-01 13:07  The_Wind_Rises  阅读(276)  评论(0编辑  收藏  举报