Pass enums in angular2 view templates

后端 未结 4 1413
清歌不尽
清歌不尽 2020-12-13 07:58

Can we use enums in an angular2 view template?

4条回答
  •  Happy的楠姐
    2020-12-13 08:34

    Create a property for your enum on the parent component to your component class and assign the enum to it, then reference that property in your template.

    export class Parent {
        public dropdownTypes = DropdownType;        
    }
    
    export class Dropdown {       
        @Input() public set dropdownType(value: any) {
            console.log(value);
        };
    }
    

    This allows you to enumerate the enum as expected in your template.

    
    

提交回复
热议问题