angular - 我们如何使用 TypeScript mixin 和依赖注入?
问题描述
当我使用mixins进行多重继承时,如果在我继承的任何类中都有依赖注入,我该如何使用super()?
代码示例:
混音:
export const applyMixins = (derivedCtor: any, baseCtors: any[]) => {
baseCtors.forEach(baseCtor => {
Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name));
});
});
};
AsyncComponent 构造函数:
export class AsyncComponent {
constructor(private communication: CommunicationsService) {}
}
界面:
export interface DashboardPageComponent extends AsyncComponent {}
构造函数:
export class DashboardPageComponent {
constructor(private myPropertiesService: MyPropertiesService, private state: StateService) {
super()
}
}
我收到以下错误:
'super' 只能在派生类中引用
另一方面,如果我通过依赖注入继承了多个类,我该如何使用 super()?
解决方案
推荐阅读
- python - 熊猫数据框操作
- python - 我正在创建一个 tkinter gui,我需要让它成为一个线程。但是线程不起作用
- algorithm - MATLAB中的牛顿求根方法:二次与三次收敛
- ajax - AJAX 的跨域域阻止错误
- aws-lambda - 在 lambda 上使用 M2Crypto 的问题(适用于 EC2)
- java - 使用填充密码解密时,输入长度必须是 8 的倍数
- ios - 绘制超过 3 个数据集时,iOS 图表不显示值标签
- ruby-on-rails - 如何根据模型上的虚拟属性返回的值搜索整个模型?
- jsp - 多个文件作为目录上传
- android - 我应该在使用 ibm watson 聊天机器人的 android 应用程序的 config.xml 中写入什么数据?