Angular2 - http.get not calling webpi

I don't know why this command works correctly, but I cannot find any call log in Fiddler ...

let z = this.http.get('http://localhost:51158/api/User/TestIT?idUser=0')

      

The code goes to this step, but if I try to catch the whole HTTP request with the fiddler, I cannot find the call ...

Do you have any idea what is going on?

thank

+3


source to share


1 answer


To start a request and receive a response, you can add map()

and .catch()

to return an Observable response from your method.

Service example:

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

getMyData(): Observable<any> {
    return this.http.get('http://localhost:51158/api/User/TestIT?idUser=0')
        .map((res: Response) => {
           console.log(res); 
           return res;
         })
         .catch((err) => { 
            // TODO: Error handling
            console.log(err); 
            return err;
     }
}

      

Then subscribe to the Observable-return method to execute the request:



Subscription example

...

this.getMyData()
        .subscribe((res: any) => {
            console.log(res);
        },
        error => {
            // TODO: Error handling
            console.log(error);
        });

      

For a good starter example, you can refer to Angular Hero Tour Example

Note: Unverified code

+4


source







All Articles