我在$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 - 做角色最直接的方式是什么?
答案 0 :(得分:2)
无需在html模板中使用{{
。
#view
<div ng-hide="logged">
// this should visible only if the logged is true
</div>
这就够了。