2014-03-01 30 views
0

我想填充StatesSelectng-options。由於我是新角色,結果並不如預期。在SELECT中不能使用ng選項

控制器

$scope.statesList = function() { 
     StatesList.query(function (states) { 
      $scope.states = states;    
     }); 
    }; 

的Html

<td data-ng-init="statesList()"> 
    <select ng-model="practiceAdd.state" name="state{{$index+1}}" ng-class="{'has-error': editForm.{{$index+1}}.$invalid}" 
     ng-options="state in states" required> 
    </select>                 
</td> 

陣列

$$hashKey: "05S" 
_id: "53107e099d985dc404000015" 
city: "mumbai" 
country: "india" 
state: "AR" 
street: "1" 
zipcode: 42101 
+0

請發帖'$ scope.states'數組來幫助我們解決它。 –

+0

嗨查幾個網址: http://docs.angularjs.org/api/ng/directive/select http://stackoverflow.com/questions/12139152/how-to-set-value-property-in- angularjs-ng-options http://stackoverflow.com/questions/13047923/working-with-ng-options-in-angular –

+0

@MaximShoustin我發佈了數組.. – Anup

回答

1

嘗試這樣的..

在HTML

<select name="countries" id="countries" ng-model="countryCode" ng-options="country.code as country.name for country in countries"></select> 

在角JS代碼

$scope.countries = [ 
    { 
     name: 'Poland', 
     code: 'PL' 
    }, 
    { 
     name: 'United Kingdom', 
     code: 'UK' 
    }, 
    { 
     name: 'United States of America', 
     code: 'USA' 
    } 
    ]; 
    $scope.countryCode = 'UK'; 

Working Exaple

在你的實施例;

<td> 
    <select ng-model="state.Id" name="state{{$index+1}}" ng-options="state.Id as state.name for state in states" required> 
    </select>                 
</td> 

狀態標識和狀態名稱應由您定義。