【问题标题】:Angular 2: what differences between comparison operators == and === in ngIf directiveAngular 2:ngIf 指令中比较运算符 == 和 === 之间的区别
【发布时间】:2016-08-26 09:26:19
【问题描述】:

我不明白为什么存在这两个运算符。在布尔比较的情况下,== 和 === 似乎都有效,但在枚举比较的情况下,只有 '==' 有效:

<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>

【问题讨论】:

  • 请查看ngIf description。关于.Net:NGif is an open-source tool that creates the ability for .Net to make/read Animated Gifs .

标签: angular operator-keyword comparator


【解决方案1】:

在 javascript 中,运算符 '==' 只检查相等性,而 '===' 检查类型和相等性

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

【讨论】:

  • 问题是关于 angular2 我认为与 javascript 无关
  • 嗯,我认为这是相关的。由于枚举在编译时存储在静态变量中。只是枚举中存储的值的类型与校验中使用的值不一样
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-01
  • 2015-07-03
  • 2011-05-24
相关资源
最近更新 更多