Javascript AngularJS默认下拉列表选择不工作
HTMLJavascript AngularJS默认下拉列表选择不工作,javascript,html,angularjs,Javascript,Html,Angularjs,HTML {{product_attribute.label} {{product_attribute.placeholder}} 上面我已经发布了我的JSON和HTML代码。我想在下拉列表中用默认的选定值显示所有的属性选项。请检查我已尝试的HTMLng selected=“option.isSelected==“true”以默认选择我的选项。但这是行不通的 截图: 您必须将defaultValue作为包含所有属性的对象。这是您的解决方案-> 例如: <div class="col-
{{product_attribute.label}
{{product_attribute.placeholder}}
上面我已经发布了我的JSON和HTML代码。我想在下拉列表中用默认的选定值显示所有的属性
选项。请检查我已尝试的HTMLng selected=“option.isSelected==“true”
以默认选择我的选项。但这是行不通的
截图:
您必须将
defaultValue
作为包含所有属性的对象。这是您的解决方案->
例如:
<div class="col-sm-6" ng-repeat="product_attribute in attributes">
<div class=" form-group">
<label class="font-noraml">{{product_attribute.label}}</label>
<select class="form-control m-b" name="option_choices" ng-selected="option.isSelected=='true'" ng-model="option.price" ng-options="option.price as option.text for option in product_attribute.choices">
<option value="">{{product_attribute.placeholder}}</option>
</select>
</div>
</div>
必须应用于选项
元素,而不是选择
,因此它与ng选项
不兼容。
<div class="col-sm-6" ng-repeat="product_attribute in attributes">
<div class=" form-group">
<label class="font-noraml">{{product_attribute.label}}</label>
<select class="form-control m-b" name="option_choices" ng-selected="option.isSelected=='true'" ng-model="option.price" ng-options="option.price as option.text for option in product_attribute.choices">
<option value="">{{product_attribute.placeholder}}</option>
</select>
</div>
</div>
"defaultValue": {
"text": "Black",
"price": "$0.00",
"isSelected": "true"
}