【发布时间】:2017-12-06 06:01:19
【问题描述】:
我无法在$rootScope 中反映我的更改。据我了解(请注意,我对angular 很陌生),$rootScope 在controllers 中可见。我要做的是更新$rootScope 中的值并尝试在我的html 页面中读取该值。
问题是即使更改已应用于$rootScope,但在我看来并没有反映出来。以下是代码
我有一个div,我想根据值显示/隐藏它
#view
<div ng-hide="{{logged}}">
// this should visible only if the logged is true
</div>
#controller1 I set the rootscope to false
$rootScope.logged = false; // this makes the view hidden
#controller2 I set the rootScope to true
$rootScope.logged = true;
$rootScope.$apply();
但是制作$rootScope.logged = true 不会使视图可见。我的问题是
1 - 我可能出了什么问题?
2 - 做这种事情最 Angular 的方式是什么?
【问题讨论】:
-
ng-hide="logged"? -
@NaeemShaikh,谢谢你成功了 :)
标签: javascript angularjs rootscope