MurhafSousli / ngx-wordpress

Angular WordPress Module ✨

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can you point to more example code?

davetbo opened this issue · comments

Hello,

As far as I can tell, this appears to be the only Wordpress API client for Angular4. Thanks for providing this great functionality.

I'm brand new to Angular and TypeScript. Can you provide an example of how to use your library to authenticate with Wordpress and execute a query for a list of posts? I know you have some brief examples in your documentation, but being new to Angular, they're too disconnected for me to piece them together into a working example.

I really appreciate your advice.

Best,
Dave

Hi @davetbo, I have already put simple examples and advanced examples.
I suggest you read the docs step by step, try the simple examples, if it did not work, then open an issue describe what you are trying to do and include your usage of the module and I will help you if I can.

Here is the simplest straight forward example I can give:

  • Generate a new empty project using Angular CLI
  • Install the module npm install --save ngx-wordpress
  • Go to the root module app.module.ts and import WordPressModule
import { WordPressModule } from 'ngx-wordpress';
@NgModule({
imports: [
    // ...
    WordPressModule.forRoot('https://example.com') //address to your WordPress site
  ]
})
  • Go to app template app.component.html and add the following:
<ul wpCollection="posts" [wpArgs]="{ }" (wpResponse)="res = $event">

   <li *ngFor="let post of res?.data"> {{ post.title.rendered }} </li>

</ul>

You should see your WordPress posts titles now

This does not work. No definition found for res:
<li *ngFor="let post of res.data"> {{ post.title.rendered }} </li>
Should there be something done in the component?

@Jscott388 Nope, you don't need to do anything from the component.
Add ? here res?.data
Look I just tested the example now

test