Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Typescript错误TS1128:应为声明或语句_Javascript_Angular_Typescript_Webpack - Fatal编程技术网

Javascript Typescript错误TS1128:应为声明或语句

Javascript Typescript错误TS1128:应为声明或语句,javascript,angular,typescript,webpack,Javascript,Angular,Typescript,Webpack,我花了几个小时试图修复一个打字脚本错误。它指向了我的游戏细节.component.ts(26,54),我觉得它非常好 此外,当我在game-detail.component网页中CTR+S成功编译并且我的程序运行良好时。谁能给我解释一下为什么会这样 代码如下: import { Component, OnInit, Input } from '@angular/core'; import { ActivatedRoute, Params } from '@angular/router'; imp

我花了几个小时试图修复一个打字脚本错误。它指向了我的游戏细节.component.ts(26,54),我觉得它非常好

此外,当我在game-detail.component网页中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;
        });
}

您没有关闭括号之间的括号。或者把括号放错地方了。取决于你想做什么

你把括号放错地方了

试试这个:

this.gameService.getGameByKey(this.gameKey).subscribe(dataLastEmittedFromObserver => {
        this.gameDetail = dataLastEmittedFromObserver;
       });

它解决了你的问题吗