我在ng-container
中添加ngIf
条件,如果条件满足,则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'
这当然没有意义——布尔值永远无法与'Land'
相比。您需要:
&& !(data.dataSubclass === 'Land')
但更明确的方法是:
&& data.dataSubclass !== 'Land'