我在这里看到了Angular select指令的文档:http : //docs.angularjs.org/api/ng.directive :select 。我不知道如何设置默认值。这令人困惑:
选择作为数组中值的标签
这是对象:
{ "type": "select", "name": "Service", "value": "Service 3", "values": [ "Service 1", "Service 2", "Service 3", "Service 4"] }
HTML(工作):
<select><option ng-repeat="value in prop.values">{{value}}</option></select>
然后我尝试在select元素内添加ng-option属性以设置prop.value为默认选项(不起作用)。
prop.value
ng-options="(prop.value) for v in prop.values"
我究竟做错了什么?
因此,假设该对象在您的范围内:
<div ng-controller="MyCtrl"> <select ng-model="prop.value" ng-options="v for v in prop.values"> </select> </div> function MyCtrl($scope) { $scope.prop = { "type": "select", "name": "Service", "value": "Service 3", "values": [ "Service 1", "Service 2", "Service 3", "Service 4"] }; }
工作的Plunkr:http://plnkr.co/edit/wTRXZYEPrZJRizEltQ2g