Ionic 3 http request
Whenever http request (using rxjs) is made from real device at that time origin and referrer received into service as undefined.
Can it is as expected behaviour of http request from real device.
import { Injectable } from '@angular/core'; import { Http } from "@angular/http"; @Injectable() export class DbcallService { constructor(private _http: Http) { } getData() { var url = 'https://jsonplaceholder.typicode.com/posts'; this._http.get(url).subscribe(data => { console.log(data); }); } }
You have to change it as shown below.
your-provider.ts
import { Injectable } from '@angular/core';
import { Http } from "@angular/http";
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
@Injectable()
export class DbcallService {
constructor(private _http: Http) {
}
getData() {
var url = 'https://jsonplaceholder.typicode.com/posts';
this._http.get(url).map(res => res.json());
}
}
When you called it, you have to do like below.
my-page.ts
this.myProvider.getData().subscribe(
result => {
},
error => { },
() => { }
);
链接地址: http://www.djcxy.com/p/47564.html
上一篇: 我如何在Angular中测试JSONP HTTP请求?
下一篇: 离子3 http请求