HappyCoding HappyCoding - 5 months ago 9
AngularJS Question

Change ng-hide value when clicking button

I'm making a small example to change the value of

ng-hide
after clicking button, but it didn't work.

I've tried:



angular.module('myModule', []).controller('myController', function ($scope) {
$scope.hide= false
$scope.change = function () {
$scope.hide = !$scope.hide
};
});

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myModule" ng-controller="myController">
<p ng-hide="{{hide}}">some text...</p>
<button ng-click="change()">change</button>
</div>





And my question: what am I missing?

Answer

Remove the brackets around hide in your template.. that will help.

ng-hide="hide"
Comments