如何将特定值设置为下拉角度方式?
问题描述:
我有一个简单的角度下拉像波纹管:如何将特定值设置为下拉角度方式?
<select class="form-control" ng-model="docPropIdentityModel.OwnerLevel"
ng-options="ownerLevel as ownerLevel.LevelName for ownerLevel in ownerLevels track by ownerLevel.OwnerLevelID">
<option value="">--Select--</option>
</select>
我已经为OwnerLevelID的值,我想要分配的OwnerLevelID为下拉&的值表示各LevelName。我可以很容易地通过使用jquery来做到这一点,但要做到这一点的角度。
我试图指派像波纹管的模型中的价值:
$scope.docPropIdentityModel.OwnerLevel = "123456";
但没有奏效。如何做到这一点?
答
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script>
<script>
angular.module("myapp", [])
.controller("MyController", function ($scope) {
$scope.register = {};
$scope.register.countryId = "4";
$scope.register.countries = [{
id: "1",
name: "India"
}, {
id: "2",
name: "USA"
}, {
id: "3",
name: "UK"
}, {
id: "4",
name: "Nepal"
}];
});
</script>
</head>
<body ng-app="myapp">
<div ng-controller="MyController">
<div>
Country Name : <select ng-model="register.countryId" ng-options="country.id as country.name for country in register.countries"></select>
</div>
<div>
Country-Id : {{register.countryId}}
</div>
</div>
</body>
</html>
'$ scope.docPropIdentityModel.OwnerLevel = {OwnerLevelID: “123456”};' – Satpal
你确定'OwnerLevelID'是'string'而不是'number'? '$ scope.docPropIdentityModel.OwnerLevel = 123456;' – Kutyel