我有一个角度js下拉列表。我希望如果我的变量,例如'x'的值为true它使得必须从下拉列表中选择一个值,并允许它保存它而不从下拉列表中选择任何内容。这是我的下拉:
WKInterfaceGroup
答案 0 :(得分:1)
<select class="form-control dropdownheight"
ng-model="search.hardware"
ng-change="search()"
ng-required="x">
<option value="" selected>Select Hardware</option>
<option ng-repeat="box in boxes" value="{{box.name}}">{{box.name}}</option>
</select>
答案 1 :(得分:1)
您可以使用此所需的ng。
<form name="form">
<select ng-model="hardware" class="form-control dropdownheight" ng-change="search()" >
<option value="" selected>Select Hardware</option>
<option ng-repeat="box in boxes" value="{{box.name}}">{{box.name}}</option>
</select>
<label for="input">This input must be filled if `required` is true: </label>
<input type="text" id="input" name="input" ng-required="isRequired" /><br>
<hr>
<code>{{form.input.$error}}</code><br>
isRequired = <code>{{isRequired}}</code>
<input type="submit" value="Save" ng-disabled="isRequired"/>
</form>
我为它创建了plunkr: