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

 e31384874 发布于 2023-02-12 14:33

我试图使用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');
        }
     }
}

儿童:

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');
        }
    }
} 

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

.controller('ParentCtrl', Controllers.ParentCtrl)
.controller('ChildCtrl', Controllers.ChildCtrl)

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

1 个回答
  • 您需要确保之前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');
            }
        }
    } 
    

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

    2023-02-12 14:35 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有