[英]Not working ng-options in SELECT
I am trying to populate States
in Select
with ng-options
. 我试图填充
States
在Select
与ng-options
。 As i am new to angular, result doesn't come as expected. 由于我是新手,因此结果并没有达到预期。
Controller 调节器
$scope.statesList = function () {
StatesList.query(function (states) {
$scope.states = states;
});
};
Html 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>
Array 排列
$$hashKey: "05S"
_id: "53107e099d985dc404000015"
city: "mumbai"
country: "india"
state: "AR"
street: "1"
zipcode: 42101
Try like This.. 尝试这样。
In HTML 在HTML中
<select name="countries" id="countries" ng-model="countryCode" ng-options="country.code as country.name for country in countries"></select>
In angular JS Code 用角JS代码
$scope.countries = [
{
name: 'Poland',
code: 'PL'
},
{
name: 'United Kingdom',
code: 'UK'
},
{
name: 'United States of America',
code: 'USA'
}
];
$scope.countryCode = 'UK';
In your Example ; 在你的例子中;
<td>
<select ng-model="state.Id" name="state{{$index+1}}" ng-options="state.Id as state.name for state in states" required>
</select>
</td>
State id and state name should be defined by you. 州ID和州名称应由您定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.