下面的代码失败,出现错误:打字稿接口无法工作
readCandidates is not a function:
下面是代码
export class Candidates {
private _dataService : ModelContracts.IDataService;
constructor(private tag: ModelContracts.ITag, private dataService: ModelContracts.IDataService) {
this._value = tag;
this._dataService = dataService;
}
private _value : ModelContracts.ITag;
public get value() : ModelContracts.ITag {
return this._value;
}
public set value(v : ModelContracts.ITag) {
this._value = v;
}
candidates = [];
activate() {
this._dataService.readCandidates().then(candidates => this.candidates = candidates);
}
}
export interface IDataService {
readCandidates(): Promise<ModelContracts.ICandidate[]>
}
export class DataService {
//some implementation
}
我使用Aurelia路上打赌1.1.0和打字稿。 dataService依赖项被注入,但函数调用失败。
在您提供的代码中没有对'getCandidates'的调用。问题必须在代码的其他部分。 – zlumer
是的,这是一个错字。我的意思是'readCanidates'... –
没有办法告诉问题是什么,如果dataService是一个有效的IDataService,它将有一个'readCandidates()'函数,并且你的应用程序可以工作。 –