我需要從db中的已保存值中更改下拉列表的「選定值」。我怎樣才能做到這一點?從角度控制器中更改下拉選擇的值
控制器
var app = angular.module('app', []);
app.controller('ctrl', function($scope) {
$scope.months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
$scope.selected='August';//here it's not working ?
});
HTML
<html ng-app="app">
<body ng-controller="ctrl">
<div class="sample" align="center">
<h1>AngularJS Combobox</h1>
<select ng-model="selected" ng-options="opt as opt for opt in months" ng-init="selected='March'"></select>
<h3>You have selected : {{selected}}</h3>
</div>
</body>
</html>
任何幫助將高度讚賞。
那麼我怎樣才能給一個默認的負載值? – Sampath 2014-11-06 11:11:27
您正在使用兩種競爭的默認聲明方法。只需使用一個 - 刪除ng-init並使用$ scope.selected選擇默認值,或者,不要完全刪除ng-init,只需將它的值更改爲'August'即可。 – 2014-11-06 11:13:01
你跑過我給你看的東西了嗎? 'ng-model =「selected」'將默認加載值設置爲您在'$ scope.selected ='August'中設置的值;' – 2014-11-06 11:13:50