Reputation: 625
I am trying to make the ng-hide or ng-show in Angular working based on a $scope variable.
The Hello
What am I doing wrong?
Controller:
angular
.module('myApp', [])
.controller('MainController', MainController);
function MainController($scope) {
$scope.state = true;
}
Html:
<body ng-controller="MainController">
<h1>Hello Plunker!</h1>
<div ng-hide"state">
<p>hello</p>
</div>
{{ state }}
</body>
Plunker link https://plnkr.co/edit/xxWVeThH8m218aS4Dago?p=preview
Upvotes: 0
Views: 747
Reputation: 220
angular.module('myApp', [])
.controller('mainController', ['$scope',
function($scope) {
$scope.state = true;
}
]);
angular.module('myApp', [])
.controller('mainController', ['$scope',
function($scope) {
$scope.state = true;
}
]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!-- need to assign value of ng-app to module name for automatically bootstrapping the angularjs application -->
<div ng-app="myApp" ng-controller="mainController">
<div ng-hide = "state"> <!-- here -->
<p>hello</p>
</div>
{{ state }}
</div>
Upvotes: 0
Reputation: 414
Syntax problem. Use ng-hide="state"
instead ng-hide"state"
angular
.module('myApp', [])
.controller('MainController', MainController);
function MainController($scope) {
$scope.state = true;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MainController">
<h1>Hello Plunker!</h1>
<div ng-hide = "state"> <!-- here -->
<p>hello</p>
</div>
{{ state }}
</div>
Upvotes: 2
Reputation: 535
You need to make it ng-hide="state".
You're missing the equals sign.
<body ng-controller="MainController">
<h1>Hello Plunker!</h1>
<div ng-hide="state">
<p>hello</p>
</div>
{{ state }}
</body>
Here's your plunker, fixed. https://plnkr.co/edit/5BY0ubF3X70yFGVVd0Po?p=preview
Upvotes: 2