我有一个模型作为
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 被视为字符串而不是数字
我该如何解决这个问题?
最佳答案
要检查类型,你必须使用 ===
,检查
*ngIf="announcementDocumentTypeId===1
关于当使用 ngIf 和 Number 类型时,Angular 期望操作符具有相似类型或任何类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46648027/