[英]Accessing $rootScope variable from a directive
So I have a directive that look like this: 因此,我有一个如下所示的指令:
(function (module) {
var node = function (RecursionHelper) {
return {
restrict: 'E',
controller: 'mainController',
scope: {
node: '=n'
},
templateUrl: '/app/NSviewer/templates/parts/node.html',
compile: function (element) {
// Use the compile function from the RecursionHelper,
// And return the linking function(s) which it returns
return RecursionHelper.compile(element);
}
};
};
module.directive("node", node);
}(angular.module("anbud")));
And I have a layout variable that is defined like this: 我有一个如下定义的布局变量:
$rootScope.layout = "test";
In the node directive. 在node指令中。 The layout variable is not displayed. 不显示布局变量。
<pre>{{layout | json}}</pre>
This shows up as empty. 这显示为空。
How can I access $rootScope.layout from my node directive? 如何从我的node指令访问$ rootScope.layout?
尝试这种方式:
<pre>{{$root.layout | json}}</pre>
Hi you need to inject $rootScope
in your directive and try it this way: 嗨,您需要在指令中注入$rootScope
并尝试使用这种方式:
{{$root.layout | json}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.