遇到 typescript 错误,我花了几个小时试图修复。它指向我的 game-details.component.ts(26,54),对我来说它看起来完全没问题。
另外,当我在我的 game-detail.component webpack 中 CTR + S 时,编译成功并且我的程序运行良好。任何人都可以向我解释为什么它会这样工作吗?
代码如下:
import { Component, OnInit, Input } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { Location } from '@angular/common';
import { GameService } from '../../game.service';
import { UserComment } from '../../comment.model';
@Component({
selector: 'app-game-detail',
templateUrl: './game-detail.component.html',
styleUrls: ['./game-detail.component.css'],
providers: [GameService]
})
export class GameDetailComponent implements OnInit {
gameKey: string;
gameDetail;
constructor(private route: ActivatedRoute, private location: Location, private gameService: GameService) { }
ngOnInit() {
this.route.params.forEach((urlParameters)=> {
this.gameKey = urlParameters['id'];
});
this.gameService.getGameByKey(this.gameKey).subscribe(dataLastEmittedFromObserver => {
this.gameDetail = dataLastEmittedFromObserver;);
}
addComment(com: string) {
const newComment: UserComment = new UserComment(com);
this.gameDetail.comments.push(newComment);
this.gameService.updateComments(this.gameDetail);
// this.toggleDisplay();
}
}
最佳答案
如果您查看您的代码,它在 ngOnInit()
中存在问题,您几乎没有错放括号,请将其更改为
ngOnInit() {
this.route.params.forEach((urlParameters) => {
this.gameKey = urlParameters['id'];
});
this.gameService.getGameByKey(this.gameKey)
.subscribe(dataLastEmittedFromObserver => {
this.gameDetail = dataLastEmittedFromObserver;
});
}
关于javascript - typescript 错误 TS1128 : Declaration or statement expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49766968/