node.js - Angular2 rest calls in background -
i created sample application per jhon papa's example.(quick start program). designed service class json data rest service http://localhost:8081//myserver/rest/heros
import { injectable } '@angular/core'; import { http, response , headers} '@angular/http'; import 'rxjs/add/operator/topromise'; import { hero } './hero'; import { code } './code'; import { heroes } './mock-heroes'; @injectable() export class heroservice { constructor(private http: http) { } private heroesurl = 'http://localhost:8081//myserver/rest/heros'; // url web api getheroes() { return this.http.get(this.heroesurl) .topromise() .then( response => response.json() hero[]) .catch(this.handleerror); } gethero(id: number) { return this.getheroes() .then(heroes => heroes.find(hero => hero.id === id)); } private handleerror(error: any) { console.error('an error occurred', error); return promise.reject(error.message || error); } }
the service class working fine , heroes listed in ui well(just forget cros orgin problem here). one-thing noticed here rest call http://localhost:8081//myserver/rest/heros directly sent browser(i can see in network tab of developer tool).
according application should not send browser, instead should processed on backend bean classes in jsf , serve data relevant component. belive resolve cros orgin problem well. dose angular2 has such option ? please suggest right way achieve it.
you can use webworkers move code execution out of main ui thread. angular2 provides direct support (experimental).
i doubt change in regard cors. cors work, server needs respond correct cors headers.
see http://www.syntaxsuccess.com/viewarticle/web-workers-in-angular-2.0
Comments
Post a Comment