2018-08-08 09:20:09

angular select下拉框 ng-options 3种默认选中方法

angular select下拉框 ng-options 3种默认选中方法

1、html代码
<div ng-controller="MyController">
    1、ng-model选中:
    <select ng-model="value">
      <option ng-repeat="item in Array">{{item}}</option>
    </select>

    2、ng-selected选中:
    <select>
      <option ng-repeat="item in Array" ng-selected="value2 == item">{{item}}</option>
    </select>

    3、ng-options:选中:
    <select ng-model="value3" ng-options="item for item in Array">
    </select>
</div>
2、js代码
<script type="text/javascript">
var myApp = angular.module('myApp', []);
    myApp.controller('MyController',['$scope', function($scope) {
      $scope.value = 'angular';
      $scope.value2 = 'vue';
      $scope.value3 = 'react';
      $scope.Array = ['JavaScript', 'react', 'angular', 'html5', 'vue'];
    }]);
</script>
注:ng-options时需要使用ng-model
当前文章内容为原创转载请注明出处:http://www.good1230.com/detail/2018-08-08/40.html
最后生成于 2024-05-27 22:52:28
此内容有帮助 ?
0