为什么 zonejs 在 angular 2.4 中用打字稿找不到我的组件
Why is my component not found by zonejs in angular 2.4 with typescript
我有一个用 Typescript 编写的 angular 2.45 项目。我在我的应用程序的路由模块中添加了一个新组件,并且还导入了新组件。
当我启动应用程序时,我收到以下错误:
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 中,我已将 Component 和 RoutingModule 添加到我的 AppModule 的声明和导入数组中。
@NgModule({
imports: [
...,
AppRoutingModule,
],
declarations: [
....,
NewComponent
],
bootstrap: [AppComponent]
)}
export class AppModule {}
对于我所有的其他组件,这完全符合预期。 Angular 找到组件,注入所需的一切并正确路由。
但是 NewComponent 根本不起作用。关于可能是什么原因的任何想法?
我发现了错误。我错误地导入了组件 newComponent。我在组件路径中的斜杠太多了。
import { NewComponent } from './components//new.component';
对
import { NewComponent } from './components/new.component';
typescript 编译器(命令行和 Visual Studio 代码版本 2.15)不关心。 Zonejs /angular 不过似乎很在意!
我有一个用 Typescript 编写的 angular 2.45 项目。我在我的应用程序的路由模块中添加了一个新组件,并且还导入了新组件。
当我启动应用程序时,我收到以下错误:
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 中,我已将 Component 和 RoutingModule 添加到我的 AppModule 的声明和导入数组中。
@NgModule({
imports: [
...,
AppRoutingModule,
],
declarations: [
....,
NewComponent
],
bootstrap: [AppComponent]
)}
export class AppModule {}
对于我所有的其他组件,这完全符合预期。 Angular 找到组件,注入所需的一切并正确路由。
但是 NewComponent 根本不起作用。关于可能是什么原因的任何想法?
我发现了错误。我错误地导入了组件 newComponent。我在组件路径中的斜杠太多了。
import { NewComponent } from './components//new.component';
对
import { NewComponent } from './components/new.component';
typescript 编译器(命令行和 Visual Studio 代码版本 2.15)不关心。 Zonejs /angular 不过似乎很在意!