angular2-force icon indicating copy to clipboard operation
angular2-force copied to clipboard

Cannot find name 'res' and other syntax errors

Open ksharifbd opened this issue 9 years ago • 1 comments

Angular 2 newbie here.

Thanks John Papa for awesome tutorial. I don't know if this is the right place to post this, but I am posting anyway.

I'm using webpack and following the ng-conf presentation. When I run npm start I get following error

ERROR in ./src/app/service/mock-data-service.service.ts
(13,25): error TS1005: '=>' expected.

ERROR in ./src/app/service/mock-data-service.service.ts
(13,27): error TS1005: ';' expected.

ERROR in ./src/app/service/mock-data-service.service.ts
(13,40): error TS1005: ';' expected.

ERROR in ./src/app/service/mock-data-service.service.ts
(13,30): error TS7027: Unreachable code detected.

ERROR in ./src/app/service/mock-data-service.service.ts
(13,30): error TS2304: Cannot find name 'res'.
Child html-webpack-plugin for "index.html":
    chunk    {0} index.html 512 kB
         + 3 hidden modules
webpack: bundle is now VALID.

and my contents in mock-data-service.service.ts are

import { Injectable } from '@angular/core';
import {Http, Response} from '@angular/http';
import 'rxjs/add/operator/map';

@Injectable()
export class MockDataService {

  constructor(private http: Http) {
  }

  getMockData() {
    return this.http.get('./src/database/mockdata.json')
    .map((res: Response)) => res.json());
  }

}

You can view the full picture here

ksharifbd avatar May 26 '16 08:05 ksharifbd

@ksharifbd you have a typo. Replace:

 .map((res: Response)) => res.json());

to

 .map((res: Response) => res.json());

piecioshka avatar Mar 03 '17 19:03 piecioshka