以下代码显示无法在angular js
中设置undefined属性'show'HTML代码
<div ng-controller="DeathRayMenuController">
<button ng-click="toggleMenu()">Toggle</button>
<ul ng-show="menuState.show">
<li ng-click="stun()">Stun</li>
<li ng-click="disintegrate()">Disintegrate</li>
<li ng-click="destroy()">Destroy</li>
</ul>
Javascript:
function DeathRayMenuController($scope) {
$scope.menuState.show = false;
$scope.toggleMenu = function() {
$scope.menuState.show = true;
}
}
在运行此操作时遇到此错误
TypeError:无法设置未定义属性'show'
答案 0 :(得分:3)
menuState
:
$scope.menuState = {
show : false
};