Javascript 安格拉斯<;选择>;问题
我有个奇怪的问题。我在我的应用程序中使用AngularJS,我的标签有问题。我有一个控制员,由我的下属处理城市和州:Javascript 安格拉斯<;选择>;问题,javascript,angularjs,Javascript,Angularjs,我有个奇怪的问题。我在我的应用程序中使用AngularJS,我的标签有问题。我有一个控制员,由我的下属处理城市和州: function MeuController($scope, $http) { $scope.states = []; $scope.selectedState = ''; $scope.cities = []; $scope.selectedCity = ''; $http.get('/state/GetStates').success(functio
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>
。。。我的元素没有填充
如果我这样做:
<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>
{{state.Name}
{{city.Name}
现在,这些值被填充到元素中。尽管如此,如果我更改“selectedState”范围变量的值,我的元素没有“选择”正确的值
有人知道为什么吗
非常感谢你 好的,所以实际上问题出在
ng型号
和ng选项
之间
当您这样做时:
<select class="span6" name="SelectedCity" ng-model="selectedCity"
ng-options="city.ID as city.Name for city in cities"></select>
请检查此表中的结果
它能解决您的问题吗?您能发布一个states数组的示例数据吗。我问这个问题是因为,如果我在本地测试它而不更改代码,那么你说不工作的选项就是工作的。是州和市都不来,还是只有州不来?