Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Unexpected value 'Http' imported by the module 'AppModule' at SyntaxError.ZoneAwareError

Tags:

angular

I've checked my code several times and tried finding similar problems on the web and stackoverflow, but I'm out of ideas by now, I simply can't see my mistake. Do you have any recommendations what I should examine next?

UPDATE: When I debug my Configuration Class I can see, that my json-Configurations files are read and the values are stored into my configuration variables correctly on App-Initialize (see load()-function of app.config.ts on plnkr). BUT if I want to get the values back from this configuration varibales e.g. line 39 of "werkzeug.service.ts"

let host:string = this.config.getConfig('host');

The following error appears:

TypeError: Cannot read property 'host' of null
    at AppConfig.getConfig (http://localhost:3000/app/app.config.js:31:27)
    at WerkzeugService.getSollIstWerkzeugBySchrankAndAnsicht (http://localhost:3000/app/werkzeug.service.js:47:32)
    at AppComponent.ngAfterViewInit (http://localhost:3000/app/app.component.js:37:30)
    at CompiledTemplate.proxyViewClass.View_AppComponent_Host0.detectChangesInternal (/AppModule/AppComponent/host.ngfactory.js:44:71)
    at CompiledTemplate.proxyViewClass.AppView.detectChanges (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:12206:18)
    at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:12353:48)
    at ViewRef_.detectChanges (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:9375:24)
    at eval (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:8299:71)
    at Array.forEach (native)
    at ApplicationRef_.tick (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:8299:29)
    at ApplicationRef_._loadComponent (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:8274:18)
    at ApplicationRef_.bootstrap (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:8262:18)
    at eval (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:8091:93)
    at Array.forEach (native)
    at PlatformRef_._moduleDoBootstrap 

Here is my project setup: http://plnkr.co/edit/QsaOtnqFr0Ky9Qwz21SP?p=preview

like image 839
anyones Avatar asked Feb 20 '17 15:02

anyones


1 Answers

HttpModule should be in the imports but Http shouldn't be.

@NgModule({
  imports:      [ BrowserModule, FormsModule, ReactiveFormsModule, HttpModule],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ],
  providers: [ AppConfig, { provide: APP_INITIALIZER, useFactory: initConfig, deps: [AppConfig], multi: true }]  
})

Example http.get Plunker: http://plnkr.co/edit/60E2qb9gOjvkEAeR5CtE?p=info

like image 151
eko Avatar answered Nov 02 '22 15:11

eko