angular.js : select默認(rèn)選項怎么設(shè)置?
問題描述
<!DOCTYPE html><html ng-app='myApp'> <head><meta charset='utf-8'><title></title><script src='http://www.aoyou183.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>
這個時候,默認(rèn)值就是 xxx 的值回答2:
試試給select的value賦值
回答3:ng-init呢 或許可以試下
回答4:如果下拉列表是在ng-controller里,要設(shè)置默認(rèn)值,需要在controller函數(shù)中添加:$scope.a = 111;
相關(guān)文章:
1. 輸入地址報以下截圖錯誤,怎么辦?2. angular.js - angularJs ngRoute怎么在路由傳遞空字符串及用ng-switch取得3. javascript - 求助一個關(guān)于indexedDB的問題4. 我何時應(yīng)該在Java中使用JFrame.add(component)和JFrame.getContentPane()。add(component)5. html5 - video ios不能播放怎么辦?6. android - xml的drawable作背景,是否會產(chǎn)生錯誤7. python - pip install出現(xiàn)下面圖中的報錯 什么原因?8. node.js - node中MYSQL的異步問題9. javascript - ie11以下單擊打開不了file,雙擊可以。求解?10. vim里的高亮javascript的javascript.vim 已經(jīng)放到syntax里了,但是不行。
