首页 > 解决方案 > 无法绑定到“ngIf”,因为它不是“gridster-item”的已知属性

问题描述

我知道这样的事情已经回答了很多次了。但我认为我的情况不同。我正在使用一个项目和一个库。该组件位于库中。我在项目中实现库组件,如下所示:

 <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>

那我就没有问题了。这告诉我图书馆没有加载。

所以,我想我的问题实际上是关于如何加载或可能预加载库?

我也懒加载使用库组件的模块。

希望,清楚,谢谢。

标签: lazy-loadingangular9

解决方案


如果你使用惰性组件并想使用导入(例如 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)

推荐阅读