angularjs为什么下拉列表中没有绑定值

时间:2016-09-23 11:21:23

标签: angularjs

这里我从DataBase中获取数据使用where条件,每个文本框显示值,但为什么下拉列表没有显示值

<select ng-options="I.CountryID as I.CountryName for I in CountryList" ng-model="CountryID">
    <option value="{{CountryName}}">{{CountryName}</option>

angular.js

 $scope.EditEmp = function (xxx) {
     GetAllCountryList(); var ser = Myservice.EditByid(xxx.Id);
     ser.then(function (d) {
         $scope.Name = xxx.Name;
         $scope.CountryID = xxx.CountryID;  //This is my Dropdownlist
         $('#modalpopup').modal('show')
     }
 }

1 个答案:

答案 0 :(得分:0)

在此处发布您在inspect element上的控制台中获得的内容

无论如何,这里有一个简单的例子,说明你想要做什么,这个片段来自angularjs网站,希望它会对你有所帮助。

angular.module('defaultValueSelect', [])
 .controller('ExampleController', ['$scope', function($scope) {
   $scope.data = {
    availableOptions: [
      {id: '1', name: 'Option A'},
      {id: '2', name: 'Option B'},
      {id: '3', name: 'Option C'}
    ],
    selectedOption: {id: '3', name: 'Option C'} //This sets the default value of the select in the ui
    };
}]);
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="defaultValueSelect" ng-controller="ExampleController">
  <form name="myForm">
    <label for="mySelect">Make a choice:</label>
    <select name="mySelect" id="mySelect"
      ng-options="option.name for option in data.availableOptions track by option.id"
      ng-model="data.selectedOption"></select>
  </form>
  <hr>
  <tt>option = {{data.selectedOption}}</tt><br/>
</div>

</html>