kevin_b
kevin_b

Reputation: 863

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

Upvotes: 0

Views: 142

Answers (1)

Simon Sch&#252;pbach
Simon Sch&#252;pbach

Reputation: 2683

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>

Upvotes: 1

Related Questions