我有一个旧的角度库,当我迁移到angular 12
并尝试构建我的库我收到以下错误:
projects/namespace/lin-folder/src/lib/components/alerts/alerts.component.ts:7:1
7 @Component({
~~~~~~~~~~~~
8 selector: 'app-alerts',
~~~~~~~~~~~~~~~~~~~~~~~~~
...
39
40 }
~
The component 'AlertsComponent' is used in the template but importing it would create a cycle: projects/namespace/lin-folder//src/lib/components/header/header.component.ts -> projects/namespace/lin-folder/src/lib/components/alerts/alerts.component.ts -> projects/namespace/lin-folder//src/lib/website.module.ts -> projects/namespace/lin-folder/src/lib/components/header/header.component.ts
有人遇到过同样的错误吗?
问题是我有一个interface
在我的声明中声明Library
main module
我的一个组件导入了interface
。所以我必须移动interface
到一个新文件并在模块文件和组件文件中共享它。
以下是组件中共享的模块代码
export interface WebsiteEnvironment {. // as this in the module file and imported in one of the component, it created the problem
restUrl?: string;
alertDelayInSeconds?: number;
loginUrl: string;
allowTokenToAllDomain?: string;
}
@NgModule({
imports: [
...
],
declarations: [
...
],
exports: [
...
],
entryComponents: [
...
]
})
export class WebsiteModule {
public static forRoot(websiteEnvironment: WebsiteEnvironment): ModuleWithProviders<WebsiteModule> {
return {
ngModule: WebsiteModule,
providers: [
...
]
};
}
constructor(@Optional() @SkipSelf() parentModule: WebsiteModule) {
if (parentModule) {
throw new Error(
...
}
}
}
直接把接口去掉了。创建一个新文件并添加该接口。在模块和组件中共享接口导入将消除循环依赖
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)