Angular Controller从不同的模块控制器调用

时间:2016-04-11 12:59:26

标签: angularjs angularjs-directive angular-services

我试图从另一个控制器调用一个控制器。两者都在不同的模块中。

var app = angular.module("WorkflowBuilder", ["ax.workflow.builder"] );

WorkflowBuilder是以下控制器所在的模块:

var AxProjectsWeb = angular.module('WorkflowBuilder', ['angularModalService', 'sticky', 'leaflet-directive', 'ui.bootstrap', 'nya.bootstrap.select', 'ngSanitize', 'ui.select']);

AxProjectsWeb.controller('KnowledgeController2',function(){});

因此控制器KnowledgeController2是我想在下面的控制器中调用的那个:

(function (ax, ng) {

    ng.module('ax.webagent.survey').directive('axSurveyFieldKnowledgeBase', AxSurveyFieldKnowledgeBase); // Name must be lowercase!!!

    function AxSurveyFieldKnowledgeBase() {

        return {
            restrict: 'A',
            scope: {
                // We don't want long names :)
                axC: '=axControl', // Bi-directional binding - to można zapodawac do kązdej dyrektywy - definiuje jak są ich wartości bindowane
                li18n: '=axI18n',
                isReadonly: '=axIsReadonly'
            },
            link: link,
            templateUrl: '../../../WorkflowBuilder/templates/survey/fields/AxSurveyFieldKnowledgeBase.html',
            controllerAs: 'vm',
            bindToController: true,
            controller: ['$controller', '$scope', 'Helpers', controller]
        }
    }

    function controller($controller, $scope, helpers) {
        var KnowledgeController2 = $scope.$new();
        var knC = $controller('KnowledgeController2', { $scope: KnowledgeController2 });

    }
});

我收到的错误是:

Error: [ng:areq] http://errors.angularjs.org/1.4.4/ng/areq?p0=KnowledgeController2&p1=not%20a%20function%2C%20got%20undefined
    at Error (native)
    at http://localhost:54486/Scripts/angular.min.js:6:416
    at pb (http://localhost:54486/Scripts/angular.min.js:22:41)
    at Sa (http://localhost:54486/Scripts/angular.min.js:22:128)
    at b.$get (http://localhost:54486/Scripts/angular.min.js:80:25)
    at new controller (http://localhost:54486/WorkflowBuilder/js/survey/fields/axSurveyFieldKnowledgeBase.js:32:19)
    at Object.e [as invoke] (http://localhost:54486/Scripts/angular.min.js:39:96)
    at b.$get.Q.instance (http://localhost:54486/Scripts/angular.min.js:80:151)
    at K (http://localhost:54486/Scripts/angular.min.js:61:140)
    at http://localhost:54486/Scripts/angular.min.js:68:475

0 个答案:

没有答案