4

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-hide
on the button and not have a function run inside of the controller.

2 Answers 2

8
<button ng-hide="showDiv"...

Should work also

Sign up to request clarification or add additional context in comments.

Comments

6

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>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.