[英]AngularJS - Set the true or false or select one option
我想设置我选择的任何内容,我想将其保存到 viewmodel,但我不知道如何将我选择的选项设置为 ng-model。 如果未选择任何值,则值为 select 之一。 可用选项是 YES (true) / NO (false)。 多谢你们
<select automationid="APR" name="cost" class="ddl" ng-model="tempDefaultCost.cost" ng-options="item.value as item.text for item in costFlyoutCtrl.trueFalseLookup"> <option value="">Select One</option> </select>
如果我正确理解了您的问题,您可以在 select 框中添加一个额外选项,该框已disabled
并selected
:
使用ng-repeat
:
<select automationid="APR" name="cost" class="ddl" ng-model="$ctrl.selectedItem">
<option value="" disabled selected>Select one</option>
<option ng-repeat="x in $ctrl.items">{{x.label}}</option>
</select>
还有ng-options
:
<select automationid="APR" name="cost"
class="ddl"
ng-model="$ctrl.selectedItem"
ng-options="x.label for x in $ctrl.items">
<option value="" disabled selected>Select one</option>
</select>
在您的 controller 中:
this.items = [{value: true, label: 'TRUE'}, {value: false, label: 'FALSE'}];
this.selectedItem;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.