How to Declare Global Variable in Angular 9/8?

How to Declare Global Variable in Angular 9/8?

In this post we will give you information about How to Declare Global Variable in Angular 9/8?. Hear we will give you detail about How to Declare Global Variable in Angular 9/8?And how to use it also give you demo for it if it is necessary.

Today, i will show you how to create global variable in angular 9/8. we can define global variable in angular 9/8 application. i will give you simple example of global variables in angular 9/8.

We always need to declare global variable file for our angular 8 application because we can set some global variable there like site title, api url etc so you can easily access any where in our application easily.

See also 

How to revoke 'git add' before 'git commit' ?

In this post we will give you information about How to revoke 'git add' before 'git commit' ?. Hear we will give you detail about How to revoke 'git add' before 'git commit' ?And how to use it also give you demo for it if it is necessary.



Sometimes you need to undo your git file before you git comment command. Because you made a some misteck or wrong code and you did git add using "git add ." command then you think how to undo your code before git commit command. But you can do that using git reset command, if you need to undo all file Or you may need to undo just one then you can do using git reset command, you can see bellow command.

Example:

 // For Spesific file

git reset

// For all files

git reset

Hope this code and post will helped you for implement How to revoke 'git add' before 'git commit' ?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

So, in this example, we will create GlobalConstants file for adding global variables in our application. in that file i added two variables as apiURL and siteTitle. I will access those variable value in my AppComponent file. you can also access all the component as you want.

Now, bellow we will create GlobalConstants as like created bellow and We will use that variables as like used in AppComponent file.

src/app/common/global-constants.ts

export class GlobalConstants {

public static apiURL: string = "https://onlinecode.org/";

public static siteTitle: string = "This is example of ItSolutionStuff.com";

}

src/app/app.component.ts

import { Component, OnInit } from '@angular/core';

import{ GlobalConstants } from './common/global-constants';

@Component({

selector: 'app-root',

templateUrl: './app.component.html',

styleUrls: ['./app.component.css']

})

export class AppComponent implements OnInit{

title = GlobalConstants.siteTitle;

constructor() {

console.log(GlobalConstants.apiURL);

}

ngOnInit() {

console.log(this.title);

}

}

Now you can check this project and run it.

It will display as like bellow:

Output:

Also see:Angular 8 Multiple Image Upload with Preview

https://onlinecode.org/

This is example of ItSolutionStuff.com

Angular is running in the development mode. Call enableProdMode() to enable the production mode.

Object

Live Reloading enabled.

I hope it can help you…

Hope this code and post will helped you for implement How to Declare Global Variable in Angular 9/8?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

9  +  1  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US