Angular 当使用带有 Number 类型的 ngIf 时,期望操作符是相似类型或任何类型
Angular Expected the operants to be of similar type or any when using ngIf with type Number
我有一个模型
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
我有一个模型
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