Angular 2:ngIf指令中的比较运算符==和===有什么区别
Angular 2: what differences between comparison operators == and === in ngIf directive
我不明白为什么会有这两个运算符。在布尔比较的情况下 == 和 === 似乎都有效,但在枚举比较的情况下只有 '==' 有效:
<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>
在javascript中,运算符'=='只检查相等性而'==='检查类型和相等性
0 == '0' => true
0 === '0' => false
我不明白为什么会有这两个运算符。在布尔比较的情况下 == 和 === 似乎都有效,但在枚举比较的情况下只有 '==' 有效:
<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>
在javascript中,运算符'=='只检查相等性而'==='检查类型和相等性
0 == '0' => true
0 === '0' => false