admin管理员组文章数量:1434921
I am trying to inherit an angularjs controller using Typescript's extends. But as soon as I extend the controller angularjs throws this error:
Error: Argument 'GenericLookupCtrl' is not a function, got undefined
Here is my simplified code of parent and child classes:
Parent first:
module Controllers.SolMan
{
export class ParentCtrl
{
constructor(
seUIConfigsCacheService: Services.CrossCutting.UIConfigsCacheService,
seHttpService: Services.CrossCutting.HttpService,
$scope: Interfaces.IParentScope,
genericServices: Services.CrossCutting.GenericService,
$pile)
{
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,
$pile,
$injector) {
super(seUIConfigsCacheService, seHttpService, $scope, genericServices, $pile);
console.log('Child');
}
}
}
Here is how the controllers are registered:
.controller('ParentCtrl', Controllers.ParentCtrl)
.controller('ChildCtrl', Controllers.ChildCtrl)
I can use plain angularjs inheritance of controllers but to call parent methods from child I have to extend the child because otherwise typescript gives error that it cannot find the method in parent.
I am trying to inherit an angularjs controller using Typescript's extends. But as soon as I extend the controller angularjs throws this error:
Error: Argument 'GenericLookupCtrl' is not a function, got undefined
Here is my simplified code of parent and child classes:
Parent first:
module Controllers.SolMan
{
export class ParentCtrl
{
constructor(
seUIConfigsCacheService: Services.CrossCutting.UIConfigsCacheService,
seHttpService: Services.CrossCutting.HttpService,
$scope: Interfaces.IParentScope,
genericServices: Services.CrossCutting.GenericService,
$pile)
{
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,
$pile,
$injector) {
super(seUIConfigsCacheService, seHttpService, $scope, genericServices, $pile);
console.log('Child');
}
}
}
Here is how the controllers are registered:
.controller('ParentCtrl', Controllers.ParentCtrl)
.controller('ChildCtrl', Controllers.ChildCtrl)
I can use plain angularjs inheritance of controllers but to call parent methods from child I have to extend the child because otherwise typescript gives error that it cannot find the method in parent.
Share Improve this question asked Dec 6, 2013 at 11:54 HarisHaris 7213 gold badges19 silver badges35 bronze badges1 Answer
Reset to default 6You need to ensure that ParentCtrl
is defined before ChildCtrl
. You can do that by properly ordering your script tags or your reference file or your requirejs config depending upon what method you are using.
Alternatively put them in the same file:
module Controllers.SolMan
{
export class ParentCtrl
{
constructor(
seUIConfigsCacheService: Services.CrossCutting.UIConfigsCacheService,
seHttpService: Services.CrossCutting.HttpService,
$scope: Interfaces.IParentScope,
genericServices: Services.CrossCutting.GenericService,
$pile)
{
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,
$pile,
$injector) {
super(seUIConfigsCacheService, seHttpService, $scope, genericServices, $pile);
console.log('Child');
}
}
}
There is more about TypeScript modules here
本文标签: javascriptCannot extend angularjs controller in typescriptStack Overflow
版权声明:本文标题:javascript - Cannot extend angularjs controller in typescript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745623865a2666850.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论