KMC
KMC

Reputation: 1742

Gets "error TS1005: ';' expected"

I'm playing with Angular JS's tutorial file and trying to add third play library from my work. I downloaded the library and put it inside node-modules directory. When run this tutorial, I get TS1005 (missing semicolon error) on the init function call. I'm not sure why I'm getting this error since the line already has semicolon. Anyone care to shed light on my mistake?

import { Component }          from '@angular/core';

export class RE {
  enabled: string;
}

export class Configuration {
  pToken: string;
  sToken: string;
  r: RE;
  e: RE;
}

@Component({
  selector: 'my-app',

  template: `
   <script type="text/javascript" src="node_modules/da/b-cl/ua.js">
   <h1>{{title}}</h1>
   <nav>
   <a routerLink="/dashboard" routerLinkActive="active">Dashboard</a>
   <a routerLink="/heroes" routerLinkActive="active">Heroes</a>
   </nav>
   <router-outlet></router-outlet>
`,
  styleUrls: ['app/app.component.css']
})

export class AppComponent {
title = 'Tour of Heroes';

rVar: RE = {
  enabled: "true",
  url: "https://...."
};  

eVar: RE = {
  enabled: "true",
  url: ""
};  

config: Configuration = {
 pToken: "aa",
 sToken: "a",
 r: this.rVar,
 e: this.eVar

};

init(config);

}

Upvotes: 0

Views: 456

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657078

You can't have

init(config);

outside a method or the constructor.

Only property and method declarations are allowed outside methods or the constructor.

This might do what you want

  export class AppComponent {
    title = 'Tour of Heroes';

    rVar: RE = {
      enabled: "true",
      url: "https://...."
    };  

    eVar: RE = {
      enabled: "true",
      url: ""
    };  

    config: Configuration = {
     pToken: "aa",
     sToken: "a",
     r: this.rVar,
     e: this.eVar

    };

    init(config:config) {
      // do some initialization here
    }

    constructor() {
      this.init(config);
    }
  }

Upvotes: 1

Related Questions