我的问题与Hide element outside the ng-view DOM based on route
非常相似如果可能,我希望有一个TypeScript
解决方案,允许从现有控制器为ng-show
之外的元素的ng-view
属性赋值。
我尝试为$rootScope
属性分配值,但在视图外的index.html中看不到。
这是我在控制器构造函数中尝试的内容:
$rootScope.isForm = "true";
在一个中,$rootScope.isForm = "false";
在另一个中。
在我的 index.html 中,我有以下内容:
<div class="navbar navbar-inverse">
....
<form <form class="navbar-form navbar-input-group" ng-show="$rootScope.IsForm">
...
</form>
...
</div>
...
<div "ng-view">
...
</div>
我应该怎么做?是否仍有使用$rootScope
的解决方案?
答案 0 :(得分:0)
您可以在控制器中获取$rootScope
并在那里进行修改。即
class FooController{
static $inject = ['$rootScope'];
constructor(public $rootScope){
// You can also do this based on some user action.
// Just a demo of how :
this.$rootScope.IsForm = true;
}
}