我在第一个div中有一个按钮,触发第二个div显示是否单击。它简单直接。但第二个div没有表现出来。
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>
控制器
$scope.showDetail = false;
$scope.toggleDetail = function() {
$scope.showDetail = !$scope.showDetail;
};
PS。我跟随http://www.w3schools.com/angular/tryit.asp?filename=try_ng_events
的例子答案 0 :(得分:1)
在你的例子中,一切似乎都没问题。如果你只是做了这么简单的事情,你不必使用控制器功能,你可以用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>