I began to use AngularJS, and I decided to make a list appear when I click on a button. My code is rather simple, but it doesn't work, and I don't understand why:
<div ng-app="myGame" ng-controller="gameCtrl">
<h1>{{showLevels}}</h1>
<p ng-show="showLevels">
<ul>
<li>Level 1</li>
<li>Level 2</li>
<li>Level 3</li>
</ul>
</p>
<button ng-click="toggle()">Begin Game !</button>
</div>
And, in the JavaScript file:
var app = angular.module("myGame", []);
app.controller("gameCtrl", function ($scope) {
$scope.showLevels = false;
$scope.toggle = function () {
$scope.showLevels = !$scope.showLevels;
};
});
The levels are always shown, whether I use the ngShow
or ngHide
directive, despite the fact that $scope.showLevels
is toggled, as I can see next to the title.
Where does this problem come from?
to div – Daniel Gpe Reyes May 28 '15 at 22:41