angular - Getting error when subscribing to promise -
i getting error when page getting loaded saying
people.ts?9320:22 syntaxerror: unexpected token <(…)peoplecomponent.apiservice.people.subscribe.error @ people.ts? 9320:22safesubscriber.__tryorunsub @ vm38600:166safesubscriber.error @ vm38600:127subscriber._error @ vm38600:77subscriber.error @ vm38600:57mapsubscriber._next @ vm38955:51subscriber.next @ vm38600:51onload @ vm38808:57zonedelegate.invoketask @ vm38526:423ngzoneimpl.inner.inner.fork.oninvoketask @ vm38628:36zonedelegate.invoketask @ vm38526:422zone.runtask @ vm38526:320zonetask.invoke @ vm38526:490
here code:
export class peoplecomponent { people: any; constructor(apiservice: api) { apiservice.people .subscribe({ next: x => (this.people = x), error: e => console.error(e), //error line 22 here! complete: () => console.log('completed!') }); } }
my api sevice:
import {injectable} 'angular2/core'; import { http } 'angular2/http'; @injectable() export class api { people: any; constructor(http: http) { this.people = http.get(require('./people.json')) .map(response => response.json()); } }
any thoughts?
you try subscribe way:
apiservice.people .subscribe( x => {this.people = x;}, e => {console.error(e);}, () => {console.log('completed!');} });
see documentation:
Comments
Post a Comment