angular - Angular2 DI accessing static properties -


i have following ts class

import { injectable } '@angular/core';

@injectable() export class config {      /**      * [authserviceurl description]      * @type {string}      */     static authserviceurl: string = 'http://localhost:3000'; } 

note authserviceurl static. how can access property in angular2s di framework if have this

constructor(private config: config) 

how access this. plus if want make config class singleton how do in angular2?

to declare config variable , use every can declare opaque-token explained on https://angular.io/docs/ts/latest/cookbook/dependency-injection.html#!#opaque-token.

declare config interface , interface provider same below :

=> config.ts

export interface config {   apiendpoint: string; }  export const config: config = {   apiendpoint  : 'http://api.url.com' }; 

=> config.provider.ts

import { opaquetoken } '@angular/core'; export let app_config = new opaquetoken('app.config'); 

use in shared module below :

=> shared.module.ts

import { ngmodule } '@angular/core';  import { config } './config'; import { app_config } './config.provider';  @ngmodule({   providers : [     {       provide : app_config,       usevalue: config     }   ] }) export class sharedmodule {} 

Comments