为什么 ng-if 不能在 mat-dialog 中工作

sad*_*iej 1 angularjs angular-ng-if angular-material angularjs-ng-if

我创建了一个 mat-dialog 组件来触发 http 响应。当我在 mat-dialog 的 html 中包含 ngIf 语句时,它不会被处理。在控制台上显示如下警告。

无法绑定到“ngIf”,因为它不是“div”的已知属性。

NgIf 在项目中的所有其他组件中运行良好。

在打字稿文件中调用 mat-dialog。

 this.matDialog.open(PaymentModelComponent, {
              width: "630px",
              data: { message: response.comment },
              autoFocus: false,
              height: "630px",
            });
Run Code Online (Sandbox Code Playgroud)

html代码

<div *ngIf="true"><p>Show this only if "show" is true</p></div>
Run Code Online (Sandbox Code Playgroud)

为什么 ng-if 不能在 mat-dialog 中工作?

Mut*_*ion 10

我所需要做的就是将 DialogComponent 添加到模块的声明中:

declarations: [..., MyDialogComponent]
Run Code Online (Sandbox Code Playgroud)

无需将组件代码放在同一文件中。