获取我花了几个小时尝试修复的打字稿错误。它指向我的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();
}
}
答案 0 :(得分:1)
如果你看一下你的代码,那么在 ngOnInit()
里面有一个问题,你几乎没有错位的paranthesis,将其更改为
ngOnInit() {
this.route.params.forEach((urlParameters) => {
this.gameKey = urlParameters['id'];
});
this.gameService.getGameByKey(this.gameKey)
.subscribe(dataLastEmittedFromObserver => {
this.gameDetail = dataLastEmittedFromObserver;
});
}
答案 1 :(得分:0)
您所做的并不是关闭括号之间的括号。或者错误地括号括起来。取决于你想做什么。
答案 2 :(得分:0)
你放错了括号。
试试这个:
this.gameService.getGameByKey(this.gameKey).subscribe(dataLastEmittedFromObserver => {
this.gameDetail = dataLastEmittedFromObserver;
});