Hi,
My provider api not working if i’m gonna use HttpClient. Please see below api provide code
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Http, RequestOptions, Headers } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class ApiProvider {
data : any;
apiUrl = 'https://jsonplaceholder.typicode.com';
constructor(public http: HttpClient) {
console.log('Hello ApiProvider Provider');
}
getUsers() {
return new Promise(resolve => {
this.http.get(this.apiUrl+'/users').subscribe(data => {
resolve(data);
}, err => {
console.log(err);
});
});
}
}
my Home.ts includes
import { ApiProvider } from '../../providers/api/api';
constructor(public navCtrl: NavController, private LoadingCtrl: LoadingController, public api: ApiProvider) {
this.getUsers();
}
getUsers() {
this.api.getUsers()
.then(data => {
this.users = data;
console.log(this.users);
});
}