【问题标题】:angularJS Hide button and textboxesangularJS隐藏按钮和文本框
【发布时间】:2016-10-07 10:22:34
【问题描述】:

我正在创建一个有两个按钮的网络应用程序。

第一个插入 第二次更新 点击这些按钮中的任何一个,我都想打开一个模式,它运行良好。

点击后弹出模态(插入或更新)

    <div class="modal fade" id="myModal" role="dialog">
        <div class="modal-dialog">

          <!-- Modal content-->
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal">&times;</button>
              <h4 class="modal-title"><p style="color:red; text-align:center;">Don't Leave Empty Field Please Fill 'N.A' There !!</p></h4>
            </div>
            <div class="modal-body">
<select>
<option>Insert Text Box</option>
<option>Update Text box</option>
</select>
<input type="text" name="insert">
<input type="text" name="update">
    </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default">Insert</button>
              <button type="button" class="btn btn-default">Update</button>
            </div>
          </div>

        </div>
      </div>

但是如果用户点击insertupdate button中的modal-footer必须是hide

如果用户选择在下拉列表中插入 update textbox 必须隐藏,如果用户选择更新 insert textbox 必须隐藏。

【问题讨论】:

  • 在您的按钮中使用 ng-hideng-show
  • 我需要在 if else 中使用 ng-hide 和 ng-show 但我不知道如何在 angularjs 中使用
  • 为什么会有 C# 标签? Javascript 远不及此。
  • 我的整个项目都在c#上

标签: javascript c# angularjs


【解决方案1】:

你需要在两个按钮上添加 ng-click 指令,并添加一个方法来关闭 modal,像这样:

<button ng-click="closeModal()" type="button" class="btn btn-default">Insert</button>

您使用的模态很可能已经有可用的方法。否则,您将需要处理控制器中的关闭部分。

【讨论】:

    【解决方案2】:

    您应该将信息保存在控制器的数据中,然后使用 ngShow 指令 (doc) 显示其中一个。

    这是一个示例,如果您有一个名为 ctrl 且带有 updateModal 布尔值的控制器。

    <button type="button" class="btn btn-default" ng-show="!ctrl.updateModal">Insert</button>
    <button type="button" class="btn btn-default" ng-show="ctrl.updateModal">Update</button>
    

    然后您必须在打开模式时更新此布尔值。

    【讨论】:

      【解决方案3】:

      您可以使用范围变量来跟踪最后按下的按钮,并使用ngShow 仅显示所需的按钮。

      但是,如果您最终有可能进一步自定义模态对话框,那么它就会变得一团糟。如果我是你,我会牺牲一点打字并创建两个模态对话框。然后,我会让操作按钮显示每个关联的模式。

      【讨论】:

        猜你喜欢
        • 2012-01-07
        • 2014-07-14
        • 1970-01-01
        • 2018-01-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多