我知道这样的回答已经被回答了很多次。但是我认为我的情况有所不同。我正在使用一个项目和一个图书馆。该组件位于库中。我正在像这样在项目中实现库组件:
<div fxLayout="column" fxFill>
<lib-component></lib-component>
</div>
该组件本身具有以下内容:
<div *ngIf="!expandedMode"></div>
但是如果我将组件实现更改为此:
<div fxLayout="column" fxFill>
<div *ngIf="true">Content to render when condition is true.</div>
</div>
那我没问题。这告诉我该库未加载。
所以,我想我的问题实际上是关于如何加载或可能预加载库的?
我也懒于加载使用库组件的模块。
希望如此,谢谢。
答案 0 :(得分:1)
如果您使用惰性组件并想使用导入(例如CommonModule),则需要在与组件相同的文件中的声明中使用目标组件创建NgModule
在lazy.component.ts
@Component({ ... })
export class LazyComponent
@NgModule({
declarations: [LazyComponent],
imports: [ModuleYouNeedToImport]
})
export class SomeModule {}
在other.component.ts
import('./lazy.component.ts').then(({ LazyComponent }) => LazyComponent)