angular 的 select 中 ng-options 设置默认值
发布时间:2020-12-17 09:47:30 所属栏目:安全 来源:网络整理
导读:angular 的 select 中 ng-options 设置默认值 在 AngularJS 开发的后台 web系统 中,经常需要对后台数据进行修改,而在修改数据的过程中,若页面中有 select 下拉框,需要让其选中原来的数据,即 select 中需要设置默认值。 默认值设置方法: 在 select 中使
angular 的 select 中 ng-options 设置默认值在 默认值设置方法:
代码如下: angular.module('myApp',[]) .controller('MyController',['$scope'],function($scope) { $scope.colors = ['black','white','red','blue','yellow']; $scope.myColor = $scope.colors[2]; }) <div ng-controller="MyController"> <select ng-model="myColor" ng-options="color for color in colors"></select> </div> 显示效果: 说明: 该文档参考angular官方api (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |