you can use nativescript http with angular , following example:
first import http serves in the top of the service component
var http = require("http");
in the sevice.ts file ,you need to convert the http promise to observable .
//GET Example
getList(): Observable<News[]> {
return Observable.fromPromise(
http.getJSON(serverConfig.apiUrl+"news")
).map(function(res:any) {
console.log('finished sendign request');
return res as News[]
} );
}
//POST EXAMPLE
submitFormData(data): Observable<Forms> {
let url:string=serverConfig.apiUrl+"forms/";
let headers:any = { 'Content-Type': 'application/json', 'Authorization': 'Bearer '+this.appSettings.getString("access_token")};
let req:any={
url:url,
method: "post",
headers:headers,
content: JSON.stringify(data)
};
return Observable.fromPromise(
http.getJSON(req)
).map(function(res:any) {
return res as Forms
} );
}
then you can subscribe to the observeable as you used befor,
this.newsService.getList().subscribe((res) => {
this.news= res;
});
Note : now you can remove the import statment of angular http since its not needed