vendredi 20 septembre 2019

How to compare ENUMS in Angular?

I've stored some Enums and I'd like to compare them in my frontend.

Here are my Enums:

src/shared/models/report/data-type.enum.ts
export enum DataType {
  DASHBOARD = 'DASHBOARD',
  REPORT = 'REPORT',
  APP = 'APP',
}

In my component, I'd like to compare if it's an APP or some other value. If it's an APP Enum, I'd like to show an other button in my frontend.

src/shared/components/report-modal/report-modal.component.ts

readonly isApplication = this.DataType.APP === true

Here is the code of the html component:

src/shared/components/report-modal/report-modal.component.html
      <div *ngIf="!hasNoAccess && isApplication" >
        <a class="button"
           [class.button--primary]="hasAccess"
           [class.button--secondary]="!hasAccess"
           [attr.href]="report.link"
           aria-describedby="access-btn-hint"
           target="_blank">REPORT.GO_TO_APP</a>
      </div>
      <div *ngIf="!hasNoAccess && !isApplication" >
        <a class="button"
           [class.button--primary]="hasAccess"
           [class.button--secondary]="!hasAccess"
           [attr.href]="report.link"
           aria-describedby="access-btn-hint"
           target="_blank">REPORT.GO_TO_REPORT</a>
      </div>

How can I make that work? THX

Aucun commentaire:

Enregistrer un commentaire