Angular 2 Global Constants Provider Injector Method

后端 未结 3 2010
谎友^
谎友^ 2021-02-20 05:36

I have a global constants like root directory that I want every component to have access to. In another stackoverflow question the answer was to create a constants class and imp

3条回答
  •  忘了有多久
    2021-02-20 05:51

    import {Component,bind,provide} from 'angular2/core';
    
    import {bootstrap} from 'angular2/platform/browser';
    import {FORM_DIRECTIVES} from 'angular2/form';
    import {Directive, ElementRef, Renderer, Input,ViewChild,AfterViewInit} from 'angular2/core';
    import {Constants} from 'src/constants'
    import {ViewChild, Component, Injectable} from 'angular2/core';
    
    @Component({
    selector: 'my-app', 
      template: `{{test}}`,
    })
    
    
    export class App {
        test: string;
    
        constructor(cs:Constants){
            this.test = cs.root_dir;
        }
    }
    
    bootstrap(App, [Constants]);
    

    Demo

提交回复
热议问题