3
我有一個奇怪的問題。我在我的應用中使用AngularJS,並且遇到了標籤問題。我有一個控制器有我的元素處理的城市和州:AngularJS <select>問題
function MeuController($scope, $http) {
$scope.states = [];
$scope.selectedState = '';
$scope.cities = [];
$scope.selectedCity = '';
$http.get('/state/GetStates').success(function(result) {
$scope.states = result;
});
$scope.getCities = function() {
$http.get('/cities/GetCitiesByState?state=' + $scope.selectedState).success(function(result) {
$scope.cities = result;
});
}
});
在這一點上,一切都好,容易理解。但是......
當我創建我的內容是這樣的:
<select class="span2" name="SelectedState" ng-model="selectedState"
ng-change="getCities()" ng-options="state.ID as state.Name for state in states">
<option></option>
</select>
<select class="span6" name="SelectedCity" ng-model="selectedCity"
ng-options="city.ID as city.Name for city in cities">
<option></option>
</select>
...我的要素沒有填寫。
如果我試着這樣說:
<select class="span2" name="SelectedState" ng-model="selectedState"
ng-change="getCities()">
<option ng-repeat="state in states" value="state.ID">{{state.Name}}</option>
</select>
<select class="span6" name="SelectedCity" ng-model="selectedCity">
<option ng-repeat="city in cities" value="city.ID">{{city.Name}}</option>
</select>
現在值填入的元素。雖然,如果我更改「selectedState」範圍變量的值,我的元素不會「選擇」正確的值?
任何人都知道爲什麼?
非常感謝!
你可以發佈狀態數組的樣本數據嗎?我問這個因爲,你說不工作的選項工作,如果我在本地測試它沒有任何改變你的代碼。國家和城市是不是來了,還是隻有國家不來? – rajkamal 2013-03-13 20:58:41