Javascript AngularJS:点击后隐藏按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31527897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 06:48:09  来源:igfitidea点击:

AngularJS: Hide button after click

javascriptangularjs

提问by wsfuller

New to Angular and struggling with how to do things the "Angular Way". All I want to do is click a button to show a hidden element inside a view then hide the button that was clicked. Any help would be awesome.

Angular 的新手,并且在如何以“Angular 方式”的方式做事方面苦苦挣扎。我想要做的就是单击一个按钮以显示视图内的隐藏元素,然后隐藏被单击的按钮。任何帮助都是极好的。

HTML:

HTML:

<button class="btn btn-primary" ng-click="showDiv=true; hideMe()">
  Show Div
</button>
<div ng-show="showDiv">
  I was hidden now you see me, but how do I hide the button?
</div>

Controller:

控制器:

  $scope.hideMe = function(){
    console.log('hide the button');
    $scope.hide();
  }

Code sample: Plunker

代码示例:Plunker

Ideally would like to incorporate

理想情况下想合并

ng-hide
在按钮上并且没有在控制器内部运行的功能。

回答by Kendall ARNEAUD

<button ng-hide="showDiv"...

Should work also

也应该工作

回答by code

Just add ng-show="!showDiv"to your button, this will hide it if showDiv = true

只需添加ng-show="!showDiv"到您的按钮,如果 showDiv = true,这将隐藏它

Just to be clear new html should look:

为了清楚起见,新的 html 应该看起来:

<button class="btn btn-primary" ng-click="showDiv=true" ng-show="!showDiv">Show Div</button>