无法在打字稿中扩展angularjs控制器

Har*_*ris 4 javascript inheritance angularjs typescript angularjs-controller

我试图使用Typescript的extends继承一个angularjs控制器.但是一旦我扩展控制器angularjs就会抛出这个错误:

错误:参数'GenericLookupCtrl'不是函数,未定义

这是我的父类和子类的简化代码:

家长:

module Controllers.SolMan
{
    export class ParentCtrl
    {
        constructor(
            seUIConfigsCacheService: Services.CrossCutting.UIConfigsCacheService,
            seHttpService: Services.CrossCutting.HttpService,
            $scope: Interfaces.IParentScope,
            genericServices: Services.CrossCutting.GenericService,
            $compile)
        {
            console.log('parent');
        }
     }
}
Run Code Online (Sandbox Code Playgroud)

儿童:

module Controllers.SolMan {

    export class ChildCtrl extends ParentCtrl {
        constructor(
            seUIQueryConfigsCacheService: Services.CrossCutting.UIConfigsCacheService,
            seHttpService: Services.CrossCutting.HttpService,
            $scope: Interfaces.IChildScope,
            genericServices: Services.CrossCutting.GenericService,
            $compile,
            $injector) {
                super(seUIConfigsCacheService, seHttpService, $scope, genericServices, $compile);
                console.log('Child');
        }
    }
} 
Run Code Online (Sandbox Code Playgroud)

以下是控制器的注册方式:

.controller('ParentCtrl', Controllers.ParentCtrl)
.controller('ChildCtrl', Controllers.ChildCtrl)
Run Code Online (Sandbox Code Playgroud)

我可以使用控制器的纯angularjs继承,但是从子调用父方法我必须扩展子节点,因为否则typescript会给出错误,它无法在父节点中找到该方法.

bas*_*rat 6

您需要确保之前ParentCtrl已定义.您可以通过正确排序脚本标记或参考文件或requirejs配置来实现,具体取决于您使用的方法. ChildCtrl

或者将它们放在同一个文件中:

module Controllers.SolMan
{
    export class ParentCtrl
    {
        constructor(
            seUIConfigsCacheService: Services.CrossCutting.UIConfigsCacheService,
            seHttpService: Services.CrossCutting.HttpService,
            $scope: Interfaces.IParentScope,
            genericServices: Services.CrossCutting.GenericService,
            $compile)
        {
            console.log('parent');
        }
     }
}
module Controllers.SolMan {

    export class ChildCtrl extends ParentCtrl {
        constructor(
            seUIQueryConfigsCacheService: Services.CrossCutting.UIConfigsCacheService,
            seHttpService: Services.CrossCutting.HttpService,
            $scope: Interfaces.IChildScope,
            genericServices: Services.CrossCutting.GenericService,
            $compile,
            $injector) {
                super(seUIConfigsCacheService, seHttpService, $scope, genericServices, $compile);
                console.log('Child');
        }
    }
} 
Run Code Online (Sandbox Code Playgroud)

这里有更多关于TypeScript模块的信息