javascript - 使用 ng-hide 和 radio 隐藏元素?

标签 javascript angularjs

我有一台 radio :

<div class="row">
  <div class="col15">
    <input type="radio" id="client_yes" name="client" ng-model="entry.client" ng-required="true" value="yes"><label for="client_yes">Yes</label>
  </div>
  <div class="col15">
    <input type="radio" id="client_no" name="client" ng-model="entry.client" ng-required="true" value="no"><label for="client_no">No</label>
  </div>

</div>

当选择 client_yes 时,我希望使用 ng-hide 隐藏表单上的一些问题。

我已经查看了文档中的示例:

http://docs.angularjs.org/api/ng.directive:ngHide

这使用复选框来隐藏:

ng-hide="checked"

选中的是复选框的 ng-model 名称,我只是不确定如何使用 radio ,因为它们具有相同的型号名称?

最佳答案

在问题 div 上使用 ng-hide 指令,如下所示:

ng-hide="entry.client=='yes'"

查看骗子:http://plnkr.co/edit/o2dXzq3lTGy4iBPxS6MT?p=preview

这是 HTML 代码:

  <body ng-app="app" ng-controller="Controller">
    <div class="row">
      <div class="col15">
        <input type="radio" id="client_yes" name="client" ng-model="entry.client" ng-required="true" value="yes" />
        <label for="client_yes">Yes</label>
      </div>
      <div class="col15">
        <input type="radio" id="client_no" name="client" ng-model="entry.client" ng-required="true" value="no" />
        <label for="client_no">No</label>
      </div>

      <div class="col15" ng-hide="entry.client=='yes'">
      question to hide
      </div>
      <div class="col15">
      question NOT to hide
      </div>
      <div class="col15" ng-hide="entry.client=='yes'">
      question to hide
      </div>
    </div>
  </body>

关于javascript - 使用 ng-hide 和 radio 隐藏元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20125283/

相关文章:

javascript - 如何动态设置 Angular 下拉值?

javascript - 创建 Function.prototype.theSame 以便 f() 可以作为 f.theSame() 调用

javascript - JS 在 `display: none` 和 `display: flex` 之间切换

angularjs - 将 AngularJS 1.x 项目从 gulp & bower 迁移到 webpack 3 时如何构建统一的 $templateCache

angularjs - 如何在不首先导航到 index.html 的情况下直接进入带有 ui-router 的状态

javascript - 如何使用 Angular UI Bootstrap 工具提示

javascript - 如何按字母顺序获取json文件数据

javascript - 有没有办法将数据存储在 CSS 样式声明或 CSS 规则中?

javascript - 在更改第一个选定项时显示第二个下拉菜单

javascript - 带有区域折叠的 Easyui 布局