jebmarcus jebmarcus - 7 months ago 42
HTML Question

Simple ng-click not working

I have a button in the fist div that triggers the second div to show if clicked. It is simple and straight forward. But the second div does not show.

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. I followed example from http://www.w3schools.com/angular/tryit.asp?filename=try_ng_events

Answer

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

<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>