Setup Angular 15 environment variables

 Setup Angular 15 environment variables

In this tutorial, we'll look at how to set up environment variables in Angular 15 and bootstrap for UI styling.

Before we continue, let's add our Contentful Space ID and Access Token to our Angular 15 application's environment variables.

Note: You can create an access token using the Contentful web app or the Content Management API.

Adding environment variables in Angular 15

Open the src/environments.ts file and update it as follows:

export const environment = {
  production: false,
  contentful: {
    spaceId: 'YOUR_SPACE_ID',
    accessToken: 'YOUR_ACCESS_TOKEN'

Make sure to replace YOUR_SPACE_ID and YOUR_ACCESS_TOKEN with your actual credentials.

Installing the necessary dependencies

Let's continue by installing some necessary dependencies such as contentful, bootstrap, rich-text-types and rich-text-html-renderer using the following commands after navigating to your project's folder:

npm install contentful bootstrap 
npm install @contentful/rich-text-types @contentful/rich-text-html-renderer

We'll use contentful to connect with Contentful APIs and bootstrap for styling the Angular 15 UI.

Adding Bootstrap to Angular 15

Next, let's add Bootstrap to our project. There are various ways to add Bootstrap to Angular 15, in our case, we'll include bootstrap files via the angular.json file so go ahead and open the configuration file that exists at the root of the project and add the following line:

"styles": [

Add a Bootstrap header bar

Open the src/app/app.component.html file and update it as follows:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <h1>Developers Jobs</h1>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>

We simply removed the boilerplate markup except the router outlet and added a Bootstrap header bar.

In the next tutorial, we'll learn how to develop a service for communicating between our Angular 15 app and the headless CMS backend.

✋If you have any questions about this article, ask them in our GitHub Discussions 👈 community. You can also Gitter

✋ Want to master Angular 14? Read our angular tutorial and join our #DailyAngularChallenge where we learn to build components, directives, services, pipes and complete web, mobile, and desktop applications with latest Angular version.

✋ Make sure to join our Angular 14 Dev Community 👈 to discuss anything related to Angular development.

❤️ Like our page and subscribe to our feed for updates!

Find a list of emojis to copy and paste