Select based on enum in Angular2

前端 未结 11 2107
别那么骄傲
别那么骄傲 2020-11-28 23:26

I have this enum (I\'m using TypeScript) :

export enum CountryCodeEnum {
    France = 1,
    Belgium = 2
}

I would like to build a

11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 23:28

    This is the best option which you can apply without any pipes or extra code.

    import { Component } from '@angular/core';
    
     enum AgentStatus {
        available =1 ,
        busy = 2,
        away = 3,
        offline = 0
    }
    
    
    @Component({
      selector: 'my-app',
      template: `
      

    Choose Value

    You entered {{AgentStatus[myValue]}}

    ` }) export class AppComponent { options : string[]; myValue: AgentStatus; AgentStatus : typeof AgentStatus = AgentStatus; ngOnInit() { var x = AgentStatus; var options = Object.keys(AgentStatus); this.options = options.slice(options.length / 2); } parseValue(value : string) { this.myValue = AgentStatus[value]; } }

提交回复
热议问题