繁体   English   中英

从指令访问$ rootScope变量

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM