Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EXCEPTION: Response with status: 0 for URL: null in angular2

I'm getting following exception, when I'm trying to connect to remote API using anguar2 http. Also my web server is receiving request and responding properly.

I'm able to make a successful curl request to the local server.

EXCEPTION: Response with status: 0 for URL: null

service.ts

getAllProducts(): Observable<string> {
      return this.http.get(this.productUrl)
      .map(this.extractData)
}

private extractData(res: Response) {
    let body = res.json();
    console.log(body)
    return body.data || { };
}
like image 686
Asif Avatar asked Jul 09 '16 20:07

Asif


1 Answers

I had the same error with a MEAN2 app. All I had to do was install the CORS middleware and use it with express.

like image 110
mansoor.khan Avatar answered Oct 19 '22 13:10

mansoor.khan