2017-02-03 47 views
0

我有一个用Typescript编写的角度为2.45的项目。我向应用程序的路由模块添加了一个新组件,并且还导入了新组件。为什么我的组件未能通过zonejs以角度2.4与typescript发现

当我开始我收到以下错误应用:

Unhandled Promise rejection: Component NewComponent is not part of any NgModule or the module has not been imported into your module. ; Zone: <root> ; Task: Promise.then ; Value: ZoneAwareError Error: Component NewComponent is not part of any NgModule or the module has not been imported into your module. 
    at new Error (native) 
    at JitCompiler._createCompiledHostTemplate (http://localhost:3000/static/src/assets/js/lib/@angular/compiler/bundles/compiler.umd.js:27482:23) [<root>] 
    at eval (http://localhost:3000/static/src/assets/js/lib/@angular/compiler/bundles/compiler.umd.js:27448:41) [<root>] 
    at Array.forEach (native) [<root>] 
    at eval (http://localhost:3000/static/src/assets/js/lib/@angular/compiler/bundles/compiler.umd.js:27446:49) [<root>] 
    at Array.forEach (native) [<root>] 
    at JitCompiler._compileComponents (http://localhost:3000/static/src/assets/js/lib/@angular/compiler/bundles/compiler.umd.js:27435:47) [<root>] 
    at createResult (http://localhost:3000/static/src/assets/js/lib/@angular/compiler/bundles/compiler.umd.js:27333:23) [<root>] 
    at Zone.run (http://localhost:3000/static/src/assets/js/lib/zone.js/dist/zone.js:113:43) [<root> => <root>] 
    at http://localhost:3000/static/src/assets/js/lib/zone.js/dist/zone.js:535:57 [<root>] 
    at Zone.runTask (http://localhost:3000/static/src/assets/js/lib/zone.js/dist/zone.js:151:47) [<root> => <root>] 
    at drainMicroTaskQueue (http://localhost:3000/static/src/assets/js/lib/zone.js/dist/zone.js:433:35) [<root>] 
ZoneAwareError 

这是我在我的应用程序路由模块做:

const routes: Routes = 
[ 
    // common routes 
    { 
     path: 'NewComponent', 
     component: NewComponent 
    }, 
    .... 
]; 
@NgModule({ 
    imports: [RouterModule.forRoot(routes)], 
    exports: [RouterModule] 
}) 
export class AppRoutingModule { } 

,并在我的AppModule我添加的组件和RoutingModule到我的AppModule的声明和imports数组。

@NgModule({ 
    imports: [ 
    ..., 
    AppRoutingModule, 
], 
declarations: [ 
    ...., 
    NewComponent 
], 
bootstrap: [AppComponent] 
)} 
export class AppModule {} 

对于我所有的其他组件,这完全按照预期工作。 Angular发现组件,注入所需的所有东西并正确路由。

但是NewComponent不起作用。任何可能的原因的想法?

回答

0

我发现了这个错误。我导入了组件newComponent的错误。在组件的路径上我有太多的斜线。

import { NewComponent } from './components//new.component'; 

VS

import { NewComponent } from './components/new.component'; 

的打字稿编译器(在命令行和Visual Studio代码版本2.15),也没在意。 Zonejs /角然而似乎在乎!

相关问题