在Angular

时间:2016-06-01 08:22:08

标签: angularjs

<html ng-app="myApp">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body ng-controller="XYZController">
{{menuState.show1}}
<div>

<ul ng-show='menuState.show1'>

<li ng-click='stun()'>Stun</li>
<li ng-click='disintegrate()'>Disintegrate</li>
<li ng-click='erase()'>Erase from history</li>
</ul>
<button ng-click='toggleMenu()'>Toggle Menu</button>
</div>


<script type="text/javascript">
var show2 =false;
var app=angular.module("myApp",[]);
app.controller("XYZController",function($scope){
$scope.menuState.show1=show2;

});
</script>

</body>
</html>

在此代码中应该隐藏所有ng-click元素。 BUt它仍然显示所有。我认为我的控制器没有链接。请一些人帮助我

1 个答案:

答案 0 :(得分:0)

$ scope.menuState未定义。

试试这个:

<html ng-app="myApp">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body ng-controller="XYZController">
{{menuState.show1}}
<div>

<ul ng-show='menuState.show1'>

<li ng-click='stun()'>Stun</li>
<li ng-click='disintegrate()'>Disintegrate</li>
<li ng-click='erase()'>Erase from history</li>
</ul>
<button ng-click='toggleMenu()'>Toggle Menu</button>
</div>


<script type="text/javascript">
var show2 =false;
var app=angular.module("myApp",[]);
app.controller("XYZController",function($scope){
$scope.menuState = {}
$scope.menuState.show1=show2;

});
</script>

</body>
</html>