upendra allu
upendra allu

Reputation: 106

Can't get data from HTTP GET request Nodejs and Angular2

I'm trying to get data from my local database. local url: http://localhost:8000/

I call this in my service /getPersonalInfoData status showing 200, but I can't see any data there.

component.ts:

var data = this.personalInfoService.getPersonalInfoData()
            .subscribe(arg => this.driverData = arg);
            console.log(data);

personalInfoService:

return this.http.get('/getPersonalInfoData').map((res: Response) => { console.log(res); return res; });

backend data source API(Nodejs):

routes.get('/getPersonalInfoData',personal_info_controller.getPersonalInfoData);

Upvotes: 0

Views: 45

Answers (1)

Tejaswini Bansode
Tejaswini Bansode

Reputation: 21

In personalInfoService:-

1.import { Http, Response, Headers, RequestOptions, URLSearchParams} from'@angular/http';

2.In method add this code:

const headers = new Headers({
      'Content-Type': 'application/json',
      'Cache-control': 'no-cache',
      Expires: '0',
      Pragma: 'no-cache'
    });
    const options = new RequestOptions({ headers: headers });
    return this.http.get(Url, options).map(res => {
      return res.json();
    });

Hope this will help you.

Upvotes: 1

Related Questions