Collection service - MurhafSousli/ngx-wordpress GitHub Wiki
Use WpService to get a collection of posts, here is a basic example
constructor(public wp: WpService) { }
ngOnInit() {
this.wp.collection().posts().get(args).subscribe((res: CollectionResponse) => {
// Handle the response here
});
}
Collection Service Options:
collection = <CollectionService>this.wp.collection().endpoint(endpoint);
collection.get(args) // get a new collection of posts
collection.more() // get next page combined with previous ones
collection.next() // get next page
collection.prev() // get prev page
Advanced Example
constructor(public wp: WpService) { }
ngOnInit() {
// Get an instance of `CollectionService` so you can use it more than once.
this.collection = <CollectionService>this.wp.collection().endpoint(endpoint);
}
/** Get collection of items */
get(args) {
this.collection.get(args).subscribe((res: CollectionResponse) => {
// ...
});
}
more() {
this.collection.more().subscribe((res: CollectionResponse) => {
// res.data here is combined with any previous data
// ...
});
}