Skip to content

Commit ed6718c

Browse files
committed
fix: make angular template hierarchy example work
1 parent d29d4dd commit ed6718c

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed
Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
# Angular Template Hierarchy and Data fetching Example
22

3-
In this example we show how to implement the WordPress Template Hierarchy in Angular for use with a Headless WordPress backend using WPGraphQL.
3+
In this example we show how to implement the **WordPress Template Hierarchy in Angular** for use with a Headless WordPress backend using WPGraphQL.
44

5-
## Getting Started
5+
## Getting Started 🚀
66

77
> [!IMPORTANT]
8-
> Docker Desktop needs to be installed to run WordPress locally.
8+
> **Docker Desktop** needs to be installed to run WordPress locally.
99
1010
1. Run `npm run example:setup` to install dependencies and configure the local WP server.
11-
2. Run `npm run backend:start` starts the backend server for template fetching at http://localhost:3000/api/templates
12-
3. Run `npm run example:start` to start the WordPress server and Angular development server.
11+
2. **Configure CORS:** Create a file named **`.env`** inside the **`/backend`** directory and add the following content to set the allowed frontend URL:
12+
```
13+
FRONTEND_URL=http://localhost:4200
14+
```
15+
*(For more details on the backend service, please refer to the **`/backend/README.md`** file.)*
16+
3. Run `npm run backend:start` starts the backend server for template fetching at **http://localhost:3000/api/templates**
17+
4. Run `npm run example:start` to start the WordPress server and Angular development server.
1318
1419
> [!NOTE]
1520
> When you kill the long running process this will not shutdown the local WP instance, only Angular. You must run `npm run example:stop` to kill the local WP server.
1621
17-
## Trouble Shooting
22+
## Trouble Shooting 🛠️
23+
1824
1. I get "Page Not Found. Sorry, the page you are looking for does not exist. Please check the URL." when opening the Angular app and trying to navigate through it.
19-
- Run `npm run backend:start` and verify that http://localhost:3000/api/templates returns correct data.
20-
- Verify if you have added `/backend/.env` file with correct `FRONTEND_URL`.
21-
- check for any errors in the console
22-
2. In some cases, you might have to install @angluar/cli globally. In /example-app/ run `npm install -g @angular/cli@latest`
25+
- Run `npm run backend:start` and verify that **http://localhost:3000/api/templates** returns correct data.
26+
- **Verify that you have created the `/backend/.env` file with the correct `FRONTEND_URL`** to resolve CORS issues.
27+
- Check for any errors in the console.
28+
2. In some cases, you might have to install **`@angular/cli`** globally. In `/example-app/` run `npm install -g @angular/cli@latest`
2329
3. To reset the WP server and re-run setup you can run `npm run example:prune` and confirm "Yes" at any prompts.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FRONTEND_URL=
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import { bootstrapApplication } from '@angular/platform-browser';
1+
import { bootstrapApplication, BootstrapContext } from '@angular/platform-browser';
22
import { App } from './app/app';
33
import { config } from './app/app.config.server';
4-
5-
const bootstrap = () => bootstrapApplication(App, config);
6-
7-
export default bootstrap;
4+
const bootstrap = (context: BootstrapContext) => bootstrapApplication(App, config, context);
5+
export default bootstrap;

examples/angular/template-hierarchy-data-fetching/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
"wp:uploads:zip": "zip -r wp-env/uploads.zip wp-env/uploads"
2121
},
2222
"devDependencies": {
23-
"@wordpress/env": "^10.21.0"
23+
"@wordpress/env": "^10.34.0"
2424
}
2525
}

0 commit comments

Comments
 (0)