Created
February 26, 2017 12:37
-
-
Save MurhafSousli/a21a52093779c2b7355f5dc5d45a484c to your computer and use it in GitHub Desktop.
Getting a model with WpService
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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