javascript - Unable to create toggle effect - Angularjs -


i'm following along in tutorials angularjs , unable create toggle effect.

my console reads error: typeerror: cannot set property 'show' of undefined @ new (http://practice.dev/app.js:41:25) points line of code: $scope.menustate.show = false;

app.js

  app.controller('deathraymenucontroller',['$scope', function ($scope){             $scope.menustate.show =  false;             console.log($scope.menustate.show)              $scope.togglemenu=function(){                 $scope.menustate.show = !$scope.menustate.show;             };              $scope.stun=function(){                 console.log('stunned')             };             $scope.disintegrate=function(){                 console.log('disintegrated')             };             $scope.disintegrate=function(){                 console.log('erased')             };         }]); 

index.html

<div ng-controller='deathraymenucontroller'>             <button ng-click='togglemenu()'>toggle menu</button>             <ul ng-show='menustate.show'>                 <li><button ng-click='stun()'>stun</button></li>                 <li><button ng-click='disintegrate()'>disintegrate</button></li>                 <li> <button ng-click='erase()'>erase history</li>             </ul>         </div> 

as psl noted, $scope.menustate not defined.

before add properties object, must create object.

change second line read:

$scope.menustate = { show: false }; 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -