Reputation: 1840
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.
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
Ideally would like to incorporate
ng-hideon the button and not have a function run inside of the controller.
Upvotes: 4
Views: 24419
Reputation: 1137
Just add ng-show="!showDiv"
to your button, this will hide it if showDiv = true
Just to be clear new html should look:
<button class="btn btn-primary" ng-click="showDiv=true" ng-show="!showDiv">Show Div</button>
Upvotes: 6