[英]Show Element Using Ng-Show on Ng-Click - Angular
Using the code below I am trying to show the UL element ng-click but it does not work. 使用下面的代码,我试图显示UL元素ng-click,但是它不起作用。 There are no any errors and I don't understand why it does't work like that.
没有任何错误,我也不明白为什么它不能那样工作。
Could you please take a look and explain what is made wrong? 您能否看一下并解释错误之处?
Thanks in advance! 提前致谢!
HTML 的HTML
<body ng-controller="nsCtrl as ctrl">
<div class="question">
Click <span ng-click="ctrl.showTable();">here</span>.
</div>
<ul ng-show="self.visible = false">
<li>List Item</li>
<li>List Item</li>
<li>List Item</li>
<li>List Item</li>
</ul>
</body>
Angular 角度的
<script>
angular.module('snApp', [])
.controller('nsCtrl', [function(){
var self = this;
self.showTable = function(){
self.visible = true
}
}])
</script>
The culprit is here: 罪魁祸首在这里:
ng-show="self.visible = false"
Should be: 应该:
ng-show="ctrl.visible === false"
or, better: 或更好:
ng-show="!ctrl.visible"
or even: 甚至:
ng-hide="ctrl.visible"
As a side note: are you sure you want to show list if visible
property is false? 附带说明:如果
visible
属性为false,您确定要显示列表吗? Is it possible you did invert the test or the assignment in the controller? 是否有可能在控制器中反转了测试或分配?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.