Skip to main content

Posts

Showing posts with the label What is the Best way to Declare and Access a Global Variable in Angular 2?

What is the Best way to Declare and Access a Global Variable in Angular 2?

This post helps us to learn “Declare and Access a Global Variable in Angular 2” using “Typescript” and also share the steps to create and use of this global variables. Stayed Informed - Angular 2 Tutorials and Examples Steps – 1.      Create Global Variables. 2.      Import and Use the Global Variables in the Component. 3.      Result Create Global Variables :- “app.global.ts” import { Injectable } from '@angular/core' ; @Injectable() export class AppGlobals {     readonly baseAppUrl: string = 'http://localhost:57431/' ;     readonly baseAPIUrl: string = 'https://api.github.com/' ; } Import and Use the Global Variables in the Component:- “user.component.ts” import { Component, Injectable} from '@angular/core' ; import { CommonModule } from '@angular/common' ; import { HttpModule, Http } from '@angular/http' ; import { UserService ...