lazy-loading - 无法绑定到“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>
那我就没有问题了。这告诉我图书馆没有加载。
所以,我想我的问题实际上是关于如何加载或可能预加载库?
我也懒加载使用库组件的模块。
希望,清楚,谢谢。
解决方案
如果你使用惰性组件并想使用导入(例如 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)
推荐阅读
- php - CakePHP cronjob 返回 500 错误
- javascript - 仅向 React App 获取一次数据。页面重新加载后不再获取
- python - 我编写的代码在“if”语句中完美运行,但在“else”语句中不起作用
- jpa - 为什么子实体的 id 在 EclipseLink 的响应消息中返回 0?
- ios - Swift 的问题:可选类型 '[Int : Int]?' 的值 未拆封;你的意思是用'!' 或者 '?'?
- linux - 容器没有端口
- css - CSS在同一页面中具有不同ID的多个表
- raku - Baggy add (+) 是否适用于 MixHash 权重?
- javascript - 输入范围滑块的显示值
- ios - 在聊天视图中管理键盘