Angular 9 ng-if 和 ng-show - 始终显示元素

Angular 9 ng-if and ng-show - element is always displayed

在 Angular 9 中,我有代码要隐藏 html 元素。在打字稿中我有 public 属性:

export class UserPageComponent implements OnInit {
  public postModel: any = {};

在 Html 组件中,我想检查是否应该显示 html 元素:

<mat-video ng-if="postModel.moviePath != ''" src="{{ postModel.moviePath }}"></mat-video>

但元素 mat-video 始终显示。 当我想使用 ng-show 结果是一样的。

您正在使用 angularjs 语法,angular 应该是 ngIf 指令

<mat-video *ngIf="postModel.moviePath != ''" src="{{ postModel.moviePath }}"></mat-video>

还有NO ng-show with angular.