2

Is there a way to integrate Angular2 package with wordpress, such that I could write a page or a post (say single page) within wordpress using angular tags, and data-binding.

Although I have seen a couple of integration online, all they do is call angular 2 posts or pages using REST API, and display these on a page. What I want to achieve is to be able to create the pages/posts using Angular2.

3 Answers 3

1

You can create and edit posts and pages inside your Angular 2 module.

Any page or post creation you would do inside of your Angular 2 application would be done via the REST API, just as your page retrieval has been done.

The API allows you to create, edit, and delete pages and posts using POST and DELETE requests.

The documentation is below.

https://developer.wordpress.org/rest-api/reference/posts/#create-a-post

The required fields for post creation are title, status, and content.

You can read more about it here:

https://code.tutsplus.com/tutorials/wp-rest-api-creating-updating-and-deleting-data--cms-24883

Sign up to request clarification or add additional context in comments.

Comments

1

You can refer to this link for Angular 2 and WordPress Theme Setup, please use the latest version of node or v7.7

https://github.com/stuartkuentzel/angular2-wp-theme

Comments

0

Yes, I was recently faced with this issue.

  1. Create a folder for your angular 2 app, e.g. myapp
  2. Inside the folder create a file for a Wordpress template, e.g. myTemplate
  3. Template Name: mytemplate
  4. My great angular 2+ app */

       `get_header(); ?>
            <section class="content" id="clubnavo">
             <!--This is the main component -->
                <app-root></app-root>
             </section><!-- .content -->
        <?php get_footer(); ?> `
    

The tricky part 5. You only need the dist, src and templlate file in this folder for production. 6. Important: Set the base href to the url of your app, e.g. http://example.com/pag1/my-app-page. 7. When building, include the base href option, ng build --base-href /pag1/my-app-page/

This took me lots of time to work out after easily getting to work for the home page. You do not need the base-href option if the app is on the home page.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.