gpt4 book ai didi

html - TypeScript 错误 - 此条件将始终返回 'false',因为类型 'boolean' 和 'string' 没有重叠

转载 作者:行者123 更新时间:2023-12-02 18:46:03 26 4
gpt4 key购买 nike

我正在添加 ngIf条件 ng-container如果条件满足则 display the component

我遇到的问题是出现错误

 This condition will always return 'false' since the types 'boolean' and 'string' have no overlap.

当我将条件设置为(当我使用 not operator after && 时)

<ng-container *ngIf="data.dataClass === 'Dokes'
&& !data.dataSubclass === 'Land'"> ------------------> NOT OPERATOR

但是当我删除 ! 时代码工作正常 && !data.dataSubclass === 'Land' 中的运算符

我不知道为什么会给我这个错误。我想添加 !运算符为 I want to display component when data.dataSubclass is not equal to 'Land'

.html文件

  <div>
<ng-container *ngIf="data.dataClass === 'Dokes'
&& !data.dataSubclass === 'Land'">-----------------------------> ERRORRR

!----- BELOW IS THE COMPONENT TO DISPLAY IF ABOVE CONDITION IS TRUE---------!
<money-property name="Pika" [model]="data.pika"
[editMode]="!!dataEditService.editMode">
<dl>
<dd *ngFor="let d of data.pika; index as i">
<edit-link dataClass="Dokes"
[(selectedElement)]="data.pika[i]" [editMode]="!!dataEditService.editMode"></edit-link>
</dd>

</dl>
</money-property>
</ng-container>
</div>

最佳答案

添加 ! 会破坏您尝试实现的逻辑,因为它会取反就在右边 的值。这:

&& !data.dataSubclass === 'Land'

相当于

&& (!data.dataSubclass) === 'Land'

这当然没有意义 - bool 值永远不会与 'Land' 进行比较。你需要:

&& !(data.dataSubclass === 'Land')

但更清晰的方法是:

&& data.dataSubclass !== 'Land'

关于html - TypeScript 错误 - 此条件将始终返回 'false',因为类型 'boolean' 和 'string' 没有重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67428660/

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