gpt4 book ai didi

javascript - 无法在 typescript 中扩展angularjs Controller

转载 作者:搜寻专家 更新时间:2023-10-30 20:55:38 24 4
gpt4 key购买 nike

我正在尝试使用 Typescript 的扩展继承一个 angularjs Controller 。但是只要我扩展 Controller ,angularjs 就会抛出这个错误:

Error: Argument 'GenericLookupCtrl' is not a function, got undefined

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

家长优先:

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

child :

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 的注册方式如下:

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

我可以使用 Controller 的普通 angularjs 继承,但要从子项调用父方法,我必须扩展子项,否则 typescript 会给出错误,它无法在父项中找到方法。

最佳答案

您需要确保 ParentCtrl ChildCtrl 之前定义。您可以通过根据您使用的方法正确排序脚本标签或引用文件或 requirejs 配置来做到这一点。

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

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 modules here的内容

关于javascript - 无法在 typescript 中扩展angularjs Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20423245/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com