2017-09-11 1 views
0

Wenn ich meine App (ng serve) serve, dann ConfigurationService.coucou() gibt erwarteten Wert zurück. Aber wenn ich mit --prod (ng dienen --prod), Fenster ['config'] ['Coucou'] im Konstruktor von AppModule, bekomme ich den erwarteten Wert, aber WertConfigurationService.coucou() gibt eine leere Zeichenfolge zurück .InjectionToken leer in Prod

Irgendeine Idee?

AppModule:

import { BrowserModule } from '@angular/platform-browser'; 
import { NgModule } from '@angular/core'; 
import { FormsModule } from '@angular/forms'; 
import { HttpModule } from '@angular/http'; 

import { AppComponent } from './app.component'; 

import { ConfigurationService, COUCOU } from './configuration.service'; 

@NgModule({ 
    declarations: [ 
    AppComponent 
    ], 
    imports: [ 
    BrowserModule, 
    FormsModule, 
    HttpModule 
    ], 
    providers: [ConfigurationService,{ provide: COUCOU, useValue: window['config']['coucou'] }], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 

configuration.service:

import { Injectable, Inject, InjectionToken } from '@angular/core'; 

export const COUCOU = new InjectionToken<string>('coucou'); 

@Injectable() 
export class ConfigurationService { 
    private _coucou: string; 

    get coucou(): string { 
     return this._coucou; 
    } 

    constructor(@Inject(COUCOU) coucou: string) { 
     console.log('ConfigurationService.coucou : ' + coucou); 
     this._coucou = coucou ? coucou : ""; 
    } 
} 

Antwort

0

Ich denke, Ihr Problem ist hier:

this._coucou = coucou ? coucou : ""; 

Es sollte wie folgt aussehen:

this._coucou === coucou ? coucou : ""; 
Verwandte Themen