angular - 错误 : Unexpected value 'Http' imported by the module 'AppModule' at SyntaxError. ZoneAwareError

标签 angular

我已经多次检查我的代码并尝试在网络和 stackoverflow 上找到类似的问题,但我现在已经没有想法了,我根本看不出我的错误。您对我接下来应该检查的内容有什么建议吗?

更新:当我调试我的配置类时,我可以看到,我的 json-Configurations 文件被读取并且值在 App-Initialize 上正确地存储到我的配置变量中(参见 load()-function of app.config.ts在 plnkr 上)。 但是如果我想从这个配置变量中取回值,例如“werkzeug.service.ts”的第 39 行

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

出现如下错误:

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 

这是我的项目设置:http://plnkr.co/edit/QsaOtnqFr0Ky9Qwz21SP?p=preview

最佳答案

HttpModule 应该在 imports 中,但 Http 不应该。

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

示例 http.get 插件:http://plnkr.co/edit/60E2qb9gOjvkEAeR5CtE?p=info

关于angular - 错误 : Unexpected value 'Http' imported by the module 'AppModule' at SyntaxError. ZoneAwareError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42348200/

相关文章:

typescript - Angular 2 RC4 RxJS 崩溃

angular - 在 Angular/Typescript 中的 *ngFor 中添加一个 if else 子句

javascript - Angular 6 中的 (keydown) 事件的多键绑定(bind)

css - 如何根据内容设置背景图像(固定图案可重复)和背景颜色可变(DIV)

javascript - Angular 6 自定义元素与父 DOM 交互

angular - 使用filter()代替ofType()可以吗

javascript - 以 Angular 将文件转换为 uInt8Array

css - 在单个 NgStyle 标签中混合多个条件?

Angular 6.1.9 嵌套路由到命名导出 - 'Cannot match any routes' 错误

angular - Angular 中 window.location.href 的等价物是什么