最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Typescript ERROR TS1128: Declaration or statement expected - Stack Overflow

programmeradmin0浏览0评论

Getting a typescript error that I spent a couple hours trying to fix. It's pointing at my game-detailsponent.ts(26,54) and it looks totally fine to me.

Also when I CTR + S in my game-detailponent webpack Compiles successfully and my program works fine. Can anyone explain to me why it works like that?

Here is the code:

import { Component, OnInit, Input } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { Location } from '@angular/mon';

import { GameService } from '../../game.service';
import { UserComment } from '../../ment.model';

@Component({
  selector: 'app-game-detail',
  templateUrl: './game-detailponent.html',
  styleUrls: ['./game-detailponent.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(: string) {
      const newComment: UserComment = new UserComment();
      this.gameDetailments.push(newComment);
      this.gameService.updateComments(this.gameDetail);
      // this.toggleDisplay();
    }
}

Getting a typescript error that I spent a couple hours trying to fix. It's pointing at my game-details.ponent.ts(26,54) and it looks totally fine to me.

Also when I CTR + S in my game-detail.ponent webpack Compiles successfully and my program works fine. Can anyone explain to me why it works like that?

Here is the code:

import { Component, OnInit, Input } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { Location } from '@angular/mon';

import { GameService } from '../../game.service';
import { UserComment } from '../../ment.model';

@Component({
  selector: 'app-game-detail',
  templateUrl: './game-detail.ponent.html',
  styleUrls: ['./game-detail.ponent.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(: string) {
      const newComment: UserComment = new UserComment();
      this.gameDetail.ments.push(newComment);
      this.gameService.updateComments(this.gameDetail);
      // this.toggleDisplay();
    }
}
Share Improve this question edited Jun 8, 2023 at 21:07 OneCricketeer 192k20 gold badges142 silver badges268 bronze badges asked Apr 11, 2018 at 5:14 Nicko Dela CruzNicko Dela Cruz 191 gold badge1 silver badge2 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 3

If you look at your code it has an issue inside the ngOnInit() where you have few misplaced paranthesis, change it as

ngOnInit() {
  this.route.params.forEach((urlParameters) => {
            this.gameKey = urlParameters['id'];
        });      
  this.gameService.getGameByKey(this.gameKey)
  .subscribe(dataLastEmittedFromObserver => {
            this.gameDetail = dataLastEmittedFromObserver;
        });
}

What you did is not close the bracket between parenthesis. Or misplaced the parenthesis. Depends on what you wanted to do.

You misplaced your brackets.

Try this:

this.gameService.getGameByKey(this.gameKey).subscribe(dataLastEmittedFromObserver => {
        this.gameDetail = dataLastEmittedFromObserver;
       });
发布评论

评论列表(0)

  1. 暂无评论