Below is my code from provider:
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import { WpApiPosts, WpApiMedia, WpApiUsers } from 'wp-api-angular';
/*
Generated class for the WpProvider provider.
See https://angular.io/docs/ts/latest/guide/dependency-injection.html
for more info on providers and Angular DI.
*/
export class Post {
public media_url: Observable<string>;
constructor(public authorId: number, public id: number, public title: string, public content: string, public exxerpt: string, public date, public mediaId?: number) {}
}
export class User {
constructor(public id: number, public name: string, public userImageUrl: string) {}
}
@Injectable()
export class WpProvider {
users: User[];
constructor(public wpApiPosts: WpApiPosts, public wpApiMedia, public wpApiUsers: WpApiUsers) {
this.wpApiUsers.getList()
.map(res =>res.json())
.subscribe(data => {
this.users = [];
for (let user of data) {
let oneUser = new User(user['id'], user['name'], user['avatar_urls'] ['96']);
this.users.push(oneUser);
}
})
}
}