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.lshqa.cn/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. java - yuicompressor-maven-plugin 合并可用卻不壓縮, 哪配置不對(duì)?2. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?3. linux - mysql源碼安裝遇到的問題4. dockerfile - [docker build image失敗- npm install]5. mysql - msyql 判斷字段不為空 簡(jiǎn)單方法6. docker gitlab 如何git clone?7. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””8. javascript - Vue 自定義控件v-model雙向綁定9. angular.js使用$resource服務(wù)把數(shù)據(jù)存入mongodb的問題。10. css - chrome下a標(biāo)簽嵌套img 顯示會(huì)多個(gè)小箭頭?
