angular - 组件模板错误中的 ngIf 条件?
问题描述
我在组件中收到此错误BlockComponent
:
无法绑定到“ngIf”,因为它不是“app-adresat-list”的已知属性。
组件BlockComponent
有模板:
<app-adresat-list *ngIf="element.tag === 'ADRESATS'" [parentBlock]="parentBlock" [list]="element?.children"></app-adresat-list>
为什么*ngIf
对组件不起作用,它有时会发生,但并非总是如此?
我已经检查了BlockComponent
在 app.module 中注册的内容。
我试图在此替换模板:
<div *ngIf="true">Done</div>
有效,为什么?
所有代码是:
<ng-container *ngFor="let element of documentBlock?.children">
<ng-container *ngIf="element.type === fielType.Block">
<app-block [parentBlock]="documentBlock?.children" [element]="element"></app-block>
</ng-container>
</ng-container>
解决方案
请从提供组件的模块中导入 CommonModule。
import { CommonModule } from '@angular/common';
import { BrowserModule } from '@angular/platform-browser';
@NgModule(
{ imports: [CommonModule],
declarations: [MyComponent]
... })
class MyComponentModule {}
推荐阅读
- c# - EditorCoroutine 上的非阻塞 GUI
- algorithm - 找到经常出现的数字的最佳 O(n) 算法?
- sql - 我正在尝试运行 dba_hist_plan 查询来查找特定的架构对象
- wpf - WPF。嵌套模式对话框
- php - 如何在两个函数之间进行数组合并?
- excel - 允许用户在 3 组单元格中输入一个条目(每个表格一个)
- php - laravel如何解析紧凑变量
- python - Python Qt5 - 为 mysql 查询传递变量
- angular - 表单组中表单数组中的角度订阅值更改
- react-native - OnPress 从循环中改变组件的样式- React Native with hooks