Cannot approach Typescript enum within HTML

前端 未结 5 442
生来不讨喜
生来不讨喜 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:39

    You can bind as text if enum defined as below (those values won't enforce a json string value coming from API)

      export enum SomeEnum {
          Failure,
          Success,
      }
    

    In .ts file

    public status: SomeEnum;

    In .html

    Another way, tested in Angular 8+ is to have enums with numbers

      export enum SomeEnum {
          Failure = 0,
          Success = 1,
      }
    

    In .ts file

    public status: SomeEnum;

    In .html

提交回复
热议问题