-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;
};
Alvaro Silvino
  • 9,441
  • 12
  • 52
  • 80

2 Answers2

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
};
Anik Islam Abhi
  • 25,137
  • 8
  • 58
  • 80
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.

V31
  • 7,626
  • 3
  • 26
  • 44