-
Notifications
You must be signed in to change notification settings - Fork 18
Model
Murhaf Sousli edited this page Oct 15, 2018
·
3 revisions
Use @WpModel
decorator whenever you want to perform CRUD operations
-
endpoint: Required parameter to set the endpoint target, e.g.
posts
Get a single post by id
import { Component } from '@angular/core';
import { WpModel, WpModelRef } from '@ngx-wordpress/core';
@Component({
selector: 'app-single-post-page',
template: `
<div *ngIf="wpModel.state | async; let state">
<span *ngIf="state.error" class="error">{{ state.error.message }}</span>
<span *ngIf="state.loading" class="spinner">Loading...</span>
<div *ngIf="state.data" class="post">
<div class="post-title">{{ state.data.title }}</div>
<div class="post-content" [innerHTML]="state.data.content"></div>
</div>
</div>
`,
})
export class SinglePostPageComponent {
@WpModel('posts') wpModel: WpModelRef;
ngOnInit() {
this.wpModel.get(17).subscribe();
}
}
Name | Description |
---|---|
state | Stream that emits collection state |
data | Stream that emits collection data array |
loading | Stream that emits collection loading state |
error | Stream that emits when an error occurs |
get(id) | Get a single object by id |
create(body) | Create an object |
update(id, body) | Update an existing object by id |
delete(id) | Delete an existing object by id |
destroy() | Closes the state stream and un-subscribers all its subscriptions |