【发布时间】:2019-07-04 01:21:49
【问题描述】:
我有一个 Angular (4.3.2) 应用程序,我想在其上执行 AOT 构建。应用程序是使用@angular/cli 创建的。我有两个以ng generate 为脚手架的组件和一个模块,两者都作为声明包含在其中:
import {PrivateComponent} from './private.component/private.component';
NgModule({
imports: [
// other imports
PrivateRoutingModule
],
declarations: [
...some other components,
PrivateComponent,
AppTopBarComponent
]
// other stuff
})
export class PrivateModule {}
模块的路由也用到了私有组件:
const routes: Routes = [
{path: '', component: PrivateComponent, children: // other components}
]
@NgModule({
imports: [RouterModule.forChild(routes)] // this is the Angular built-in router module
})
export class PrivateRoutingModule {}
注意路由是如何在另一个模块中定义并导入到PrivateModule
AppTopBarComponent 在PrivateComponent's 模板中使用。所以两者都被使用和声明。但是当我使用 "node_modules/.bin/ngc" -p tsconfig-aot.json(我在 Windows 10 上)时,我收到以下错误消息:
Cannot determine the module for class PrivateComponent in (path-to-project)/src/app/pages/private/private.component/private.component.ts! Add PrivateComponent to the NgModule to fix it.
Cannot determine the module for class AppTopBarComponent in (path-to-project)/src/app/pages/private/app.topbar.component.ts! Add AppTopBarComponent to the NgModule to fix it.。我的tsconfig-aot.json 文件与Angular AOT build guide 中的完全相同。
【问题讨论】:
-
值得一提的是我遇到了几个关于此事的问题,但问题主要是未使用的组件。我的实际使用过。
-
您忘记在 import import {PrivateComponent} from './private.component/private.component' 中添加 PrivateComponent;
-
@Vega 我的错,我只是在复制粘贴时错过了它。它实际上存在于源代码中
-
NgModule 的第一个 @ 也是?:)
标签: angular typescript angular-cli aot angular-aot