2017-01-05 70 views
-1

enter image description hereenter image description here這裏我使用WebApi,Mvc和Angularjs Bootstrap在這裏我成功地將數據加載到DropdownList但是爲什麼選擇dropdown select defalut lastvalue。爲什麼選擇動態下拉選擇上一個值Bydafults?

<select ng-model="CountryName" ng-options="I.CountryID as I.CountryName for I in CountryList" class="form-control"> 
              <option value="-1" selected="selected">Select Country</option> 
             </select> 

ctrls.Js

function GetCountryList() { 
    var ctrlList = MyService.GetCountrys(); 
    ctrlList.then(function (d) { 
     $scope.CountryList = d.data; 
    }) 
} 
+0

你在'd.data'中有什麼?我的意思是'$ scope.CountryList' –

+0

您是否在'$ scope.CountryName'中分配了任何值? –

+0

我只是編輯我的代碼請參閱圖像 –

回答

0

在剛剛刪除-1值:

<select ng-model="CountryName" ng-options="I.CountryID as I.CountryName for I in CountryList" class="form-control"> 
     <option value="">Select Country</option> 
</select> 

沒有必要的selected

+0

甚至不是工作 –

+0

這對我很好。更改爲我的代碼時遇到了什麼問題。 – SaiUnique

+0

我沒有安裝該應用程序。只是做一個小提琴/猛擊。 – SaiUnique