How to access an enum value in an Angular 5 view

前端 未结 3 1402
我在风中等你
我在风中等你 2020-12-19 00:06

I am currently referencing the enum int value directly in my html view, but I would prefer to reference by the enum name - for example, as I do in

3条回答
  •  长情又很酷
    2020-12-19 00:36

    You can create a method for returning string representation of enum element in your component, like:

    getActionName(): string {
        return Action[this.action];
      }
    

    And in html template call it like:

     
    

    When your declared enum is like:

        export enum Action {
      update, create
    }
    

提交回复
热议问题