Storyblok is the first headless CMS that works for developers & marketers alike.
Welcome to Storyblok and Angular 13 in 5 minutes. In this tutorial, we will learn how to integrate our headless CMS, Storyblok, with Angular 13. Following straightforward steps will create all the necessary components and develop the integration with the Storyblok SDK storyblok-js-client.
In the end, you will have a live preview to manage your content in Storyblok:
Before we get to the code go to Storyblok and create a new space:
Setup the project
In this tutorial we will use the angular-cli 13. You can check your cli version using ng version in your terminal.
Now we can start and create our project:
If all went well, enter the commands:
Wait for the server to compile and go to http://localhost:4200. Here you should see something like this:
Great! Now, let's install the Storyblok js client. You should end with version 4.2.1 or superior
And our dynamic component. Here we should get version 10.1 or superior
Awesome! Now, we need to create several files for our project. Don’t worry, we will see how each of them should look
In the end, we should have a file structure similar to this:
Ok, let’s start with our Storyblok service ../src/app/services/storyblok.service.ts. It will be in charge of talking to the Storyblok API, and should look like this:
As you can see, we need a preview token. Let's see how we can find it. Let's go to the space we created at the beginning of this tutorial
Now let's take a look at ../src/app/directives/storyblok.directive.ts. This file should look like this
In our ../src/app/app.component.html, replace the placeholder with:
Now, the file ../src/app/components.ts will be in charge of loading our components.
Let’s update our ../src/app/app.module.ts file to include the new components:
Now, to finish the component configuration, open ../src/app/app.component.ts and add the following code:
Rendering Components/Content
We have almost everything ready. Now we will add the code to render content coming from the Storyblok API.
Page component
To have in mind ⚠️
We are using dynamic imports, so we must change our ../tsconfig.json to target your code to esnext module
Teaser Component
Grid Component
Feature Component
Some final touches
Add the Storyblok bridge to ../src/index.html. It will communicate via iframe with Storyblok to tell the editing interface which component needs to be opened when the user clicks on it
Add some styles
Now that everything is set, we can start working in our content
Let's add a new preview URL
Done!
Now you can see your site and start editing your content
Marco is a Developer Relations Engineer at Storyblok. From Medellín, Colombia, he has more than 20 years of experience in software development as a Full Stack Developer.
We use cookies to learn how you interact with our content, and show you relevant content and ads based on your browsing history. You can adjust your settings below. Here's our policy.