Answers for "global variable angular"

0

global variable angular

//Use a shared service:
import { Injectable } from '@angular/core';

@Injectable()
export class AppService{
    myGlobalVar;

    constructor(){
      this.myGlobalVar = true;
      alert("My intial global variable value is: " + this.myGlobalVar);
    }

    setMyGV(val: boolean){
      this.myGlobalVar = val;
    }

    getMyGV(val: boolean){
      return this.myGlobalVar;
    }
}
//Remember to add it to the app.module providers
Posted by: Guest on August-21-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language