0
我有一個模型的角模塊選擇值後結合選項角
$scope.employee = {}
$scope.countries={}
$scope..employee.Country_id = 10
$scope.employee.City_id = 50
然後我以下列方式結合兩個選擇元件在
$http.get("/api/initdataapi/GetCountry").success(function (data) {
$scope.countries = data;
});
$scope.$watch('employee.Country_id', function (newValue, oldValue) {
var url = "/api/initdataapi/GetByCountry/" + newValue;
$http.get(url).success(function (data) {
$scope.Cities = data;
});
問題是當頁面已加載角度綁定國家,並選擇employee.Country_id
的值,並且$watch
檢測到模型更改並觸發getCities
時,角度會將城市綁定到select元素,但它不會選擇emp loyee城市
HTML:
<div class="col-sm-3 premove">
<span>Nationality</span>
<select ng-model="employee.Country_id " >
<option ng-repeat="county in countries" value="{{county.Id}}">{{county.Name_En}}</option>
</select>
</div>
<div class="col-sm-4 premove">
<span>Place of birth -{{employee.City_Id}}</span>
<select ng-model="employee.City_Id">
<option ng-repeat="birthCity in Cities" value="{{birthCity.City_Id}}">{{birthCity.City_Ename}}</option>
</select>
</div>
我應該怎麼做才能解決這個問題?
試着改變你的模型,讓員工和他的城市在一個特定的數組中。 – sms 2015-03-31 06:55:33