Angular 2: what differences between comparison operators == and === in ngIf directive

末鹿安然 提交于 2019-12-06 02:39:08

问题


I don't understand why these two operators exist. In case of boolean comparison both == and === seem to work, but in case of enum comparison only '==' works:

<div class="interventionGroup">

    <div class="interventionGroupHeader transition_1s" (click)="onClickHeader()">
        {{GroupName}}
        <div *ngIf="expanded == true" class="expand-icon"><i class="material-icons">expand_less</i></div>  <!-- WORKS -->
        <div *ngIf="expanded === false" class="expand-icon"><i class="material-icons expand-icon">expand_more</i></div> <!-- WORKS -->
    </div>

    <button *ngIf="GroupType == GroupTypeEnum.mesInterventions">dfdsfsd</button> <!-- WORKS -->

    <div style="list-style-type:none" *ngIf="expanded === true">
        <div *ngFor="let intervention of interventions"
            (click)="onClick(intervention)"> 
            <intervention-button [intervention]="intervention"></intervention-button>
        </div>
    </div>
</div>

回答1:


In javascript, the operator '==' only check equality and '===' check type and equality

0 == '0' => true
0 === '0' => false


来源:https://stackoverflow.com/questions/39162911/angular-2-what-differences-between-comparison-operators-and-in-ngif-dire

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!