且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Angular - 类型“字符串"不可分配给类型“布尔值"

更新时间:2022-11-30 10:22:49

尝试 *ngIf="!overwrite && !!saveName"saveName 转换为一个布尔值

Try *ngIf="!overwrite && !!saveName" to cast saveName to a boolean

TypeScript 给出错误的原因大致是:您在应该使用布尔值的地方使用了字符串.

The reason TypeScript gives for the error is roughly: you are using a string where you should be using a boolean.

我认为它只发生在那种情况下的原因是因为如果你有 true || 只计算第一个(因为如果第一个为真,则整个表达式都为真,而不管其余的)

The reason I think that it only happens in that circumstance is because if you have true || anything only the first will be evaluated (because if the first is true the whole expression will true regardless of the rest)