Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果变量为true,如何强制进行下拉选择?_Javascript_Angularjs_Dropdown - Fatal编程技术网

Javascript 如果变量为true,如何强制进行下拉选择?

Javascript 如果变量为true,如何强制进行下拉选择?,javascript,angularjs,dropdown,Javascript,Angularjs,Dropdown,我有一个角js下拉列表。我希望如果我的变量,例如“x”的值为true,则必须从下拉列表中选择一个值,如果值为false,则可以允许它保存该值,而无需从下拉列表中选择任何内容。这是我的下拉列表: <select class="form-control dropdownheight" ng-model="search.hardware" ng-change="search()" > <option value="" selected>S

我有一个角js下拉列表。我希望如果我的变量,例如“x”的值为true,则必须从下拉列表中选择一个值,如果值为false,则可以允许它保存该值,而无需从下拉列表中选择任何内容。这是我的下拉列表:

<select class="form-control dropdownheight"
        ng-model="search.hardware"
        ng-change="search()" >
    <option value="" selected>Select Hardware</option>
    <option ng-repeat="box in boxes" value="{{box.name}}">{{box.name}}</option>
</select>

选择硬件
{{box.name}
使用:


选择硬件
{{box.name}

请参见

您可以为此使用所需的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:

谢谢:)我修改了它并创建了一个函数来获得所需的功能。谢谢你的帮助
     <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>