Angular 10 Define global constants Example

Angular 10 Define global constants Example

In this tutorial, we will explain to you how to define global constants in angular 10. constants mean one time declares variables that don’t change every time value.

We will give you a simple example of how to define a global constant in our angular application. when we are calling rest API at that time we use the API path. if you don’t want to repeat the API path every time then you can define the global.

Create the Constant File

first, we need to create the constant class file, after then we will define the constant in this file. for that, you can see the below example.

Import the Constant Class in the Component

now, we need to import the appSettings constant class into the app.component.ts component file. so we will import that file and check that constant value.


Run Our Angular Application

Now we will run our Angular application using the below command.


Please follow and like us: