简体   繁体   English

简单的ng-click不起作用

[英]Simple ng-click not working

I have a button in the fist div that triggers the second div to show if clicked. 我在拳头div中有一个按钮,如果单击该按钮,则会触发第二个div显示。 It is simple and straight forward. 简单而直接。 But the second div does not show. 但是第二个div没有显示。

HTML 的HTML

<div class="alert alert-danger">
    Blah
    <button ng-click = "toggleDetail()" class = "btn btn-default"> <span class = "glyphicon glyphicon-zoom-in"></span> </button>
</div>

<div class="alert alert-warning" ng-show = "showDetail">
    clicked button
</div>

Controller 控制者

$scope.showDetail = false;

$scope.toggleDetail = function() {
    $scope.showDetail = !$scope.showDetail;
};

PS. PS。 I followed example from http://www.w3schools.com/angular/tryit.asp?filename=try_ng_events 我遵循了来自http://www.w3schools.com/angular/tryit.asp?filename=try_ng_events的示例

everything seems to be Ok in your example. 在您的示例中,一切似乎都还可以。 If you just do such simple stuff you don't have to use a controller function, you can do everything in html 如果您只是做这些简单的事情而不必使用控制器功能,则可以使用html进行所有操作

<div ng-init="showDetail=false" class="alert alert-danger">
    Blah
    <button ng-click = "showDetail = !showDetail" class = "btn btn-default"> <span class = "glyphicon glyphicon-zoom-in"></span> </button>
</div>
<div class="alert alert-warning"  ng-show = "showDetail">
    clicked button
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM