无法完全外部化指令的链接功能

时间:2015-12-10 10:20:58

标签: angularjs angularjs-directive

我正在尝试外化指令的链接功能。 我能够但我无法在该函数中访问$ rootScope或$ window

现有什么::

mapModule.directive('map', function ($rootScope,$window) {
    return {
        templateUrl: resource + 'partials/maps.html',
        controller: 'mapController',
        link: function (scope, element, attrs, controllers) {
            $rootScope.something = something.
            $window.something = something 
        }
    };
});

我想要什么

function mapLinkFunction(scope, element, attrs, controllers) {
    $rootScope.something = something//$rootScope is undefined
    $window.something = something //$window is undefined
};

mapModule.directive('map', function ($rootScope,$window) {
    return {
        templateUrl: resource + 'partials/maps.html',
        controller: 'mapController',
        link: mapLinkFunction
    };
});

我尝试将它们都注入mapLinkFunction但不起作用

0 个答案:

没有答案