-2

I'm trying to change dynamically the visibility of the div with

ng-show="models.show"

the following code, was my first thoughts:

but it's not working.

html

   <div ng-init="models.show=false" ng-show="models.show"> 
        Show!
   </div>
   <button ng-click="hideshow()">Click </button>

javascript/angular

$scope.hideshow= function(){
        $scope.models.show = ($scope.model.show)?false:true;
};
2
  • which is it ....models ...or .. model?? You are using both Commented Sep 6, 2015 at 3:25
  • 'models', sorry about that Commented Sep 6, 2015 at 3:33

2 Answers 2

0

Try like this

<div ng-show="show"> 
        Show!
</div>
<button ng-click="hideshow()">Click </button>

JS

$scope.show=true;
$scope.hideshow= function(){
    $scope.show=!$scope.show
};
Sign up to request clarification or add additional context in comments.

Comments

0

You can simply do something like this:

<div ng-init="show=false">
    <div ng-show="show"> 
            Show!
    </div>
    <button ng-click="!show">Click</button>
</div>

No Need of going back to the controller in this case.

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.