`

angularjs 的select设置默认值

阅读更多
myAppModule.controller('FrmController',['$scope',function($scope){

 $scope.colors =[{name:'black', shade:'dark'},{name:'white', shade:'light'},{name:'red', shade:'dark'},{name:'blue', shade:'dark'},{name:'yellow', shade:'light'}];
 $scope.myColor ='red';}]);
<form ng-controller="FrmController">

<select ng-model="m.myColor" ng-options="color.name as color.name for color in colors">

</select>
</form>

如果写成 <select ng-model="myColor" 这样可以设置默认值, 但是提交的时候,要写上每个表单域的值, 如果写成<select ng-model="m.myColor" 只需要提交 $scropt.m 就可以, 但是这样 $scope.myColor = 'red’; 就不起作用了,有没有兼顾的写法?

3 回复

$scope.m = {myColor:’red’};

 

 

angularjs 免费视频教程已经更新完成 链接: http://pan.baidu.com/s/1sjlwRt7 密码: fy99

官网实时更新下载地址:http://bbs.phonegap100.com/thread-1574-1-1.html

 

 

$scope.m = $scope.colors[0];
<select ng-model="m" ng-options="***color ***as color.name for color in colors"> 这样居然可以一次获取到 color 对象的全部属性值;

 

本文来源于:https://cnodejs.org/topic/549007b44823a0234c9e1716

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics