无法在typescript中扩展angularjs控制器
Cannot extend angularjs controller in typescript
我正在尝试使用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会出错,无法在父对象中找到方法。
您需要确保在ChildCtrl
之前定义了ParentCtrl
。您可以根据使用的方法,通过正确排序脚本标记、引用文件或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模块的信息
相关文章:
- 如何从chrome扩展访问angularjs根范围
- 扩展AngularJS模板
- 如何扩展 Angularjs ng-include 指令
- AngularJS:复制与扩展
- 在angularjs中使用ng repeat时扩展$index的范围
- 无法在typescript中扩展angularjs控制器
- AngularJS-谷歌Chrome扩展中的动态链接断开
- 可以将AngularJS用于Chrome扩展程序的选项页面
- AngularJS和jquery折叠/扩展多个引导面板
- 在 AngularJS 代码中使用此扩展的正确方法是什么
- 将geojson数据与AngularJS可扩展UI-grid一起使用
- 从Chrome扩展注入的脚本是否可以访问页面上的javascript(angularjs)
- Chrome扩展-插入的Iframe无法访问Chrome浏览器操作或Chrome.tables或AngularJS
- AngularJS 1.4x如何扩展工厂对象
- 扩展AngularJS过滤器或构建自定义过滤器
- 在AngularJS TypeScript中扩展工厂
- 扩展AngularJs指令
- 用类似jQuery的插件扩展AngularJS
- 扩展AngularJS $resource来映射Rails rest式路由(特别是$save来创建和更新)
- 扩展angularjs日期过滤器的日期格式