2017-02-20 48 views
2

我检查了我的代码几次,试图在网络和计算器上发现类似的问题,但现在我的想法已经不存在了,我根本看不到我的错误。你有什么建议,我应该接下来检查什么?当我调试我的配置类时,我可以看到,我的json-Configurations文件被读取,并且值正确地存储到我的配置变量上App-Initialize(请参阅load() - app.config的函数。在plnkr上)。 但是如果我想从这个配置中获取数值,varibales例如的第39行 “werkzeug.service.ts” 出现错误:SyntaxError.ZoneAwareError模块'AppModule'导入的意外值'Http'

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

+0

是您的'@ NgModule'仍在进口的'Http'? – echonax

+0

尽管事实上你已经完全改变了你的问题。你没有'systemjs.config.js'你试图在你的'index.html'中导入。你也没有你的'node_modules'。您可以点击左上方的新建 - > Angular - > 2.0.x为您的angular2模板创建一个新的plunker,并且您不需要编写'.js'和'.js.map'文件 – echonax

+0

我添加了缺失文件systemjs.config.js到plnkr。 – anyones

回答

9

HttpModule应该在importsHttp不该”不要。

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

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

+0

SORRY!我之前粘贴了旧代码,我的错误,我更新了我的问题,请现在查看实际的代码。我的问题依然存在。 – anyones

+0

@anyones在你的问题中,HttpModule仍然在'providers'中。 “Http”来自你的“进口”? – echonax

+0

好吧,让我尝试在'providers'中不使用'HttpModule'。为什么不应该在那里? 'Http'来自'@ angular/http'的import {HttpModule,Http};'感谢您的关注!更新:现在我从'providers'中移除了'HttpModule',但是我仍然遇到同样的错误。 – anyones

相关问题