[英]Accessing $rootScope variable from a directive
因此,我有一個如下所示的指令:
(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")));
我有一個如下定義的布局變量:
$rootScope.layout = "test";
在node指令中。 不顯示布局變量。
<pre>{{layout | json}}</pre>
這顯示為空。
如何從我的node指令訪問$ rootScope.layout?
嘗試這種方式:
<pre>{{$root.layout | json}}</pre>
嗨,您需要在指令中注入$rootScope
並嘗試使用這種方式:
{{$root.layout | json}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.