【问题标题】:Hide radiobutton when one value is selected from Dropdownlist using angularjs使用angularjs从下拉列表中选择一个值时隐藏单选按钮
【发布时间】:2022-01-16 20:36:28
【问题描述】:

我有一个下拉列表,它将值绑定为SITEFIBEROTHERS,下面有两个单选按钮,分别命名为ApproveReject

现在我想要的是,如果从下拉列表中选择了 FIBER,我想隐藏 Reject 单选按钮。

如何使用 Angular JS 实现这一点?

下面是我的代码:

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.4/angular.min.js"></script>

<!-- dropdownlist -->

<select class="form-control" id="FiberLead_ddlUtility" ng-model="UtilityModel" ng-change="refreshAllDllCMM()">
    <option value="">Please Select</option>
    <option ng-value="UTILITY" ng-repeat="UTILITY in UTILITYS">{{UTILITY}}</option>
</select>

                                            
                                            
                                            
<!-- Radio button -->


<div class="customeRadioWrap">
    <div class="customeRadio">
        <input type="radio" id="rdApprove" name="radio-group"
               ng-value="true" ng-model="radioAppRejSelected">
        <label for="rdApprove">Approve</label>
    </div>
    <div class="customeRadio">
        <input type="radio" id="rdReject" name="radio-group"
               ng-value="false" ng-model="radioAppRejSelected">
        <label for="rdReject">Reject</label>
    </div>
    <button class="btn btn-default customBtn"
            ng-click="ConfirmApproveRejectCMM()">
      <i class="fa fa-check" aria-hidden="true"></i>
      Submit
    </button>
</div>

【问题讨论】:

    标签: html css angularjs


    【解决方案1】:

    您可以使用 ng-if 指令来实现。当实用新型值为 FIBER 时,下面的代码将隐藏拒绝按钮。

    <div class="customeRadio" ng-if="UtilityModel != 'FIBER'">
        <input type="radio" id="rdReject" name="radio-group" ng-value="false" ng-model="radioAppRejSelected">
        <label for="rdReject">Reject</label>
    </div>
    

    Demo

    【讨论】:

    • 感谢您的快速响应,我试过了,但没有按预期工作。另外,控制台没有错误
    • @BN 为您添加了 plunker 演示,请将您的代码与工作示例进行比较。
    • 是的,它在 plunker 中工作。但我不知道为什么它不能在我的应用程序中工作
    • 你知道当我更改我的代码 ng-if="UtilityModel == 'FIBER'" 然后在加载时 Reject 按钮被隐藏了。
    • 我也尝试过像这样禁用 &lt;div class="customeRadio" ng-disabled="(UtilityModel == 'FIBER')"&gt; &lt;input type="radio" id="rdReject" name="radio-group" ng-value="false" ng-model="radioAppRejSelected"&gt; &lt;label for="rdReject"&gt;Reject&lt;/label&gt; &lt;/div&gt; 但这也没有用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-10
    • 2017-05-14
    • 1970-01-01
    相关资源
    最近更新 更多