Cannot approach Typescript enum within HTML

前端 未结 5 443
生来不讨喜
生来不讨喜 2021-01-31 13:03

I made an enum with Typescript to use in MyService.service.ts MyComponent.component.ts and MyComponent.component.html.

export enum ConnectionResult {
    Succes         


        
5条回答
  •  清歌不尽
    2021-01-31 13:49

    You will have to write it in the following way in .ts file.

    enum Tenure { day, week, all }
    
    export class AppComponent {
        tenure = Tenure.day
        TenureType = Tenure
    }
    

    And now in html you can use this like

    *ngIf = "tenure == TenureType.day ? selectedStyle : unSelectedStyle"
    

    I hope it is more clear now. :)

提交回复
热议问题