javascript - Cannot make a simple http GET call in Angular2 -


i trying make simple http get request angular2 app:

    this.http.get("https://mybaseurl.com/hello")   .map(res => res.json())   .subscribe(     function(response) { console.log("success response" + response)},     function(error) { console.log("error happened" + error)},     function() { console.log("the subscription completed")}   ); 

the node.js server configured way:

app.get('/hello', function(req, res) {   res.send("hellow world"); }); 

when make call keep getting error:

    caused by: unable parse url 'https://mybaseurl.com/hello'; original error: cannot read property 'split' of undefined    @ inmemorybackendservice.parseurl (in-memory-backend.service.ts:518)     @ inmemorybackendservice.handlerequest (in-memory-backend.service.ts:279)     @ inmemorybackendservice.createconnection (in-memory-backend.service.ts:240) 

any idea doing wrong?

edit: pasting entire class code:

    import {component} '@angular/core'; import {auth} './auth.service'; import {authhttp} 'angular2-jwt'; import {http} '@angular/http'; import 'rxjs/add/operator/map';  @component({   selector: 'ping',   templateurl: 'app/ping.template.html' }) export class apiservice {    api_url: string = 'https://myapp.herokuapp.com';   message: string;    constructor(private auth: auth, private http: http, private authhttp: authhttp) {}    public ping() {      this.http.get(`${this.api_url}/hello`)       .map(res => res.json())       .subscribe((response) => {          console.log("success response" + response)         },         (error) => { console.log("error happened" + error)},         () => { console.log("the subscription completed")}     );    }     } 

=====> looks huge bug in angular2 - http requests return null, or error message describing not in required pattern. has working demo of http get love see

it looks using inmemorywebapimodule.forroot(inmemorydataservice) in @ngmodule simultaneously http.get causes uncovered urls return null , error.

setting way worked me: inmemorywebapimodule.forroot(inmemorydataservice, {passthruunknownurl: true})


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -