Angular在使用类型为Number的ngIf时,期望操作符为类似类型或任何类型

时间:2017-10-09 13:45:58

标签: angular angular2-template

我有一个模型

class AnnouncementDocument {
  Id: String;
  IsDeleted: Boolean;
  Name: String;
  TemporaryName: String;
  Description: String;
  AnnouncementDocumentTypeId: Number;
}

在我的模板中我正在使用

*ngIf="announcementDocumentTypeId==1

我收到错误

[Angular] Expected the operants to be of similar type or any

这是正确的,因为模板中的1被视为字符串而不是数字

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

要检查类型,您必须使用 === ,只需检查

*ngIf="announcementDocumentTypeId===1