angular.js : select默認(rèn)選項(xiàng)怎么設(shè)置?
問題描述
<!DOCTYPE html><html ng-app='myApp'> <head><meta charset='utf-8'><title></title><script src='http://www.b3g6.com/wenda/js/angular.min.js'></script> </head> <body ng-controller='c'><select ng-model='a' ng-change='fn()'> <option value='111'>111</option> <option value='222'>222</option> <option value='333'>333</option></select><ul> <li ng-repeat='v in value'>{{v}}</li></ul> </body> <script>var m1 = angular.module(’myApp’,[]);m1.controller(’c’,[’$scope’, ’$http’,function($scope, $http){ $scope.value = []; $scope.fn = function() {console.log($scope.a);$http.get(’get’+ $scope.a +’.txt’).success(function(data) { console.log(data); $scope.value = data;}) }}]) </script></html>

問題解答
回答1:你需要先
<select ng-model='xxx'></select>
這個(gè)時(shí)候,默認(rèn)值就是 xxx 的值回答2:
試試給select的value賦值
回答3:ng-init呢 或許可以試下
回答4:如果下拉列表是在ng-controller里,要設(shè)置默認(rèn)值,需要在controller函數(shù)中添加:$scope.a = 111;
相關(guān)文章:
1. 關(guān)于docker下的nginx壓力測試2. docker - 各位電腦上有多少個(gè)容器啊?容器一多,自己都搞混了,咋辦呢?3. mac里的docker如何命令行開啟呢?4. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””5. nignx - docker內(nèi)nginx 80端口被占用6. docker容器呢SSH為什么連不通呢?7. dockerfile - 我用docker build的時(shí)候出現(xiàn)下邊問題 麻煩幫我看一下8. docker-compose 為何找不到配置文件?9. docker start -a dockername 老是卡住,什么情況?10. angular.js使用$resource服務(wù)把數(shù)據(jù)存入mongodb的問題。

網(wǎng)公網(wǎng)安備