gpt4 book ai didi

当使用 ngIf 和 Number 类型时,Angular 期望操作符具有相似类型或任何类型

转载 作者:太空狗 更新时间:2023-10-29 17:33:34 25 4
gpt4 key购买 nike

我有一个模型作为

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com