/ngx-simple-global

A simple global variable service for Angular.

Primary LanguageTypeScriptMIT LicenseMIT

Angular Simple Global Paypal donate

A global variable service for Angular.

ngx-simple-global uses Angular CLI starting 12.2.0.

Table Of Content

Install

npm install ngx-simple-global

Usage

ngx-simple-global is implemented as Angular injectable service name SimpleGlobal.

Module

Add SimpleGlobal into module providers.

import { SimpleGlobal } from 'ngx-simple-global';

@NgModule({
    providers: [SimpleGlobal]
})

Component

import {SimpleGlobal} from 'ngx-simple-global';

export class ChildComponent {

    constructor(private sg: SimpleGlobal) { }

}

API

import {SimpleGlobal} from 'ngx-simple-global';

@Component({
    selector: 'child-com',
    template: `
        <p>This is a global variable: {{sg.gv}}</p>
        <input type="text" [(ngModel)]="sg.gv">
    `
})
export class ChildComponent {

    localVar;

    constructor(private sg: SimpleGlobal) {
        if (this.sg['gv']) {
            this.localVar = this.sg['gv'];
        }
    }

}