Skip to content
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Site Map

XpertPhp

Expertphp Is The Best Tutorial For Beginners

  • Home
  • Javascript
    • Jquery
    • React JS
    • Angularjs
    • Angular
    • Nodejs
  • Codeigniter
  • Laravel
  • Contact Us
  • About Us
  • Live Demos

Home » Angular » Angular 10 Define global constants Example

Angular 10 Define Global Constants Example

Angular 10 Define global constants Example

Posted on October 8, 2020October 18, 2020 By XpertPhp No Comments on 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.

Table of Contents

  • Create the Constant File
  • Import the Constant Class in the Component
  • Run Our Angular Application

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.
src/app/common/appSettings.ts

1
2
3
export class AppSettings {
   public static apiURL='http://127.0.0.1:8000/api/';
}

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.

src/app/app.component.ts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { Component, OnInit } from '@angular/core';
import{ appSettings } from './common/appSettings';
 
 
@Component({
 
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
 
})
 
export class AppComponent implements OnInit{
 
    constructor() {
    }
 
    ngOnInit() {
        console.log(appSettings.apiURL);
    }
}

Run Our Angular Application

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

1
ng serve

Output

1
http://127.0.0.1:8000/api/

Please follow and like us:
error
fb-share-icon
Tweet
fb-share-icon

Recommended Posts:

  • Angular 11 Add Class Dynamically Example
  • angular 10 image upload with preview image example
  • Angular 10 nested routing & Child Routes example
  • Angular 11 CRUD Application Example Tutorial
  • Angular 10 Bootstrap 4 Datepicker Example
Angular Tags:angular 10 tutorial, angular constants class

Post navigation

Previous Post: Angular 10 Form Validation Example Tutorial
Next Post: angular 10 file upload example tutorial

Latest Posts

  • Laravel Check If Foreach is Empty Example
  • Laravel Check Array Empty in Blade
  • PHP Datatables CRUD Example
  • How to Convert Date and Time from one timezone to another in php
  • how to get current date and time in php
  • Drag and Drop Reorder Items with jQuery, PHP & MySQL
  • Laravel 9 Toastr Notifications Example Tutorial
  • Laravel 9 CRUD Operation Example Using Google Firebase
  • Laravel 9 CKeditor Image Upload With Example
  • Laravel 9 Summernote Image Upload With Example

Tools

  • Compound Interest Calculator
  • Hex to RGB Color Converter
  • Pinterest Video Downloader
  • Birthday Calculator
  • Convert JSON to PHP Array Online
  • JavaScript Minifier
  • CSS Beautifier
  • CSS Minifier
  • JSON Beautifier
  • JSON Minifier

Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Javascript
  • Jquery
  • Laravel
  • MongoDB
  • MySql
  • Nodejs
  • Php
  • React JS
  • Shopify Api
  • Ubuntu

Tags

angular 10 tutorial angular 11 ci tutorial codeigniter 4 image upload Codeigniter 4 Tutorial codeigniter tutorial CodeIgniter tutorial for beginners codeigniter with mysql crud operation eloquent relationships file upload File Validation form validation Image Upload jQuery Ajax Form Handling jquery tricks jquery tutorial laravel 6 Laravel 6 Eloquent Laravel 6 Model laravel 6 relationship laravel 6 relationship eloquent Laravel 6 Routing laravel 7 Laravel 7 Eloquent laravel 7 routing laravel 7 tutorial Laravel 8 laravel 8 example laravel 8 tutorial laravel 9 example laravel 9 tutorial Laravel Framework laravel from scratch Laravel Socialite laravel social login nodejs pagination payment gateway php with mysql react js tutorial rewrite rule send mail validation wysiwyg editor

Copyright © 2018 - 2022,

All Rights Reserved Powered by XpertPhp.com