我有一个 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
The 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.
. My tsconfig-aot.json
文件与中的完全相同Angular AOT 构建指南 https://angular.io/guide/aot-compiler.
确保您不会意外地有两个文件声明相同的组件
如果我运行时位于错误的目录中,这种情况经常发生在我身上ng g c
,并且不要立即删除错误生成的文件。
错误:无法确定类的模块
FeatureBoxGroupComponent 中
S:/.../src/app/common-widgets/feature-widgets/feature-box-group/feature-box-group.component.ts!
将FeatureBoxGroupComponent 添加到NgModule 来修复它。
在这个例子中我有FeatureBoxGroupComponent
定义在两个地方:
src\app\common-widgets\feature-widgets\feature-box-group\feature-box-group.component.ts
src\app\feature-widgets\feature-box-group\feature-box-group.component.ts
当然,错误消息告诉我它有问题的确切文件 - 但很容易浏览它。
只需在文件中查找组件名称即可查看引用它的所有位置,并确保它只定义一次。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)