我想用typescript扩展一个角度工厂,所以我可以有一个特定的工厂,但是当我尝试运行时它会给我一个错误。
module App.Services {
export interface IShared {
documents: Array<any>;
}
export class Shared implements IShared {
public static serviceId = "shared";
datacontext: App.Services.IDatacontext;
documents: Array<any>;
constructor(datacontext: App.Services.IDatacontext) {
this.datacontext = datacontext;
this.datacontext.getDocuments().success((documents) => {
this.documents = documents;
});
}
}
editorApp.factory(Shared.serviceId, ['datacontext',
(datacontext) => new Shared(datacontext)
]);
}
我想将Shared类扩展到以下类
module App.Services {
export interface ITemplateShared extends IShared {
}
export class TemplateShared extends Shared implements ITemplateShared {
public static serviceId = "templateShared";
datacontext: App.Services.IDatacontext;
constructor(datacontext) {
super(datacontext);
//this.datacontext = datacontext;
}
}
editorApp.factory(TemplateShared.serviceId, ['datacontext', 'shared',
(datacontext) => new TemplateShared(datacontext)
]);
}
当我开始时,它在templateShared.js第5行第5行给出了一个未处理的异常
提前致谢!
答案 0 :(得分:0)
class TemplateShared扩展了Shared
最喜欢的问题:确保 Shared
之前浏览器加载TemplateShared
。 JavaScript / TypeScript中的加载顺序非常重要。
我建议使用外部模块以避免此错误:https://www.youtube.com/watch?v=KDrWLMUY0R0&hd=1