从指令访问$rootScope变量



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

(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>
嗨,

您需要在指令中注入$rootScope并尝试这样做:

{
{$root.layout | json}}

最新更新