gpt4 book ai didi

javascript - 从指令访问 $rootScope 变量

转载 作者:行者123 更新时间:2023-11-30 09:52:52 25 4
gpt4 key购买 nike

所以我有一个看起来像这样的指令:

(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";

在节点指令中。不显示布局变量。

<pre>{{layout | json}}</pre>

这显示为空。

如何从我的节点指令访问 $rootScope.layout?

最佳答案

试试这个方法:

<pre>{{$root.layout | json}}</pre>

关于javascript - 从指令访问 $rootScope 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35479936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com