Currently, I am following the Angular2 heroes tutorial and encountering an issue while working on the http section. The error originates from my hero.service.ts
file:
Error Message:
app/hero.service.ts(12,23): error TS1005: '(' expected.
app/hero.service.ts(12,30): error TS1005: '=' expected.
The code snippet that led to this error is as follows:
Code Snippet:
import { Injectable } from '@angular/core';
import { Headers, Http } from '@angular/http';
import 'rxjs/add/operator/toPromise';
import { Hero } from './hero';
@Injectable()
export class HeroService {
private headers: new Headers({'Content-Type': 'application/json'});
private heroesUrl: 'app/heroes'; //URL to web api
constructor(private http: Http) { }
getHeroes(): Promise<Hero[]> {
return this.http.get(this.heroesUrl)
.toPromise()
.then(response => response.json().data as Hero[])
.catch(this.handleError);
}
// More code snippets here...
I initially assumed it was a typo but even after cross-checking multiple times and trying the solution provided in their Plunker demo, the error still persists.
This suggests there might be an issue with how TypeScript is implemented in my case.
The contents of my package.json are as shown below:
package.json:
{
"name": "angular2-quickstart",
"version": "1.0.0",
"scripts": {
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},
"license": "ISC",
"dependencies": {
"@angular/common":... //More dependencies listed here
}
If anyone has insights into what may be causing the issue or can suggest a fix, I would greatly appreciate your input.
For context, I am using Windows10 as my operating system.
Thank you for your help!