这应该非常简单,但是我在Typescript中的过滤器功能一直给我一个错误。这是我的代码:
highScores: HighScore[];
deletePlayer(email: string) {
this.scoreDataService.deletePlayer(email)
.subscribe(
this.highScores = this.highScores.filter(highScore => highScore.email !== email)
);
}
过滤器函数应该只返回一个数组HighScore [],但是,我不断收到此错误:
Argument of type 'HighScore[] is not assignable to parameter of type 'NextObserver<Response> | ErrorObserver<Response> | CompletionObserver<Response> ...
Type 'HighScore[]' is not assignable to type '(value: Response) => void'. Tyope 'HighScore[]' provides no match for the signature '(value:Response): void'
最奇怪的是,即使出现此错误,该代码也可以正常运行。有人知道会发生什么吗?先感谢您!
最佳答案
subscribe
需要一个函数参数:
this.scoreDataService.deletePlayer(email)
.subscribe(() => {
this.highScores = this.highScores.filter(highScore => highScore.email !== email)
});
关于javascript - 基本的Javascript过滤器功能在Angular2中无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40139619/