Angularjs-如何从其他模块angularjs访问一个控制器(使用打字稿)

时间:2018-09-07 04:43:21

标签: angularjs typescript angularjs-controller angularjs-components

//在engagement.component.ts中:

class EngagementMembersController {
         alphabetic: Array<string> = 'abcdefghijklmnopqrstuvwxyz'.split('');
         constructor() {}

 export const EngagementSetupMember: IComponentOptions = {
    controller: EngagementMembersController,
    templateUrl: 'engagementMembers.component.html'
}

//在topbar.moudel.ts中:

import {EngagementSetupMember} from './../engagement.component';
export const topBarMembersModule: string = angular
.module('topbar-members', [])
.controller(EngagementSetupMember.controller)
.component('topbarMemberComponant', {
    require: {
        controller: '^EngagementMembersController'
    },
    templateUrl: 'topBarMembers.component.html'
})
.name;

但是当我使用它时,屏幕显示错误:

  

vendor.js:36574错误:[$ compile:ctreq]控制器   'EngagementMembersController',指令要求   找不到“ topbarMemberComponant”!

请帮助!

1 个答案:

答案 0 :(得分:0)

我认为我必须先由另一个组件调用EngagementMembersController,然后才能使用:

require: {
    controller: '^EngagementMembersController'
},

在这种情况下,我在ui_router中调用了它,可能已加载