Skip to content

Instantly share code, notes, and snippets.

@MurhafSousli
Created February 26, 2017 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MurhafSousli/a21a52093779c2b7355f5dc5d45a484c to your computer and use it in GitHub Desktop.
Save MurhafSousli/a21a52093779c2b7355f5dc5d45a484c to your computer and use it in GitHub Desktop.
Getting a model with WpService
/*
* This example demonstrates how to get a single post by id
*/
import { Component } from '@angular/core';
import { WpModel, WpPost } from "ng2-wp-api";
@Component({
selector: 'test-model',
template: `
<h1>{{post.title()}}</h1>
`
})
export class TestModel {
post;
constructor(private wpService: WpService) {
}
ngOnInit(){
let args = {
_embed: true
};
this.wpService.model().posts().get(1395, args)
.subscribe((res)=>{
if(res.error){
console.log(res.error);
}
else{
this.post = new WpPost(res.data);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment