1
我想使用枚举作为参数的方式如下:角2:枚举管材参数
<div> {{ myValue | myPipe: MyEnum.ENUM_VAL }} </div>
在控制器我已经定义MyEnum:
@Component({
selector: 'app-my-component',
templateUrl: './my.component.html',
styleUrls: ['./my.component.css']
})
export class MyComponent implements OnInit {
MyEnum: MyEnum;
....
}
我得到:TypeError:无法读取未定义的属性'ENUM_VAL'
使用它的正确方法是什么?
第一个问题:是否在任何地方定义了MyEnum *变量? – developer033
当然,在MyComponent –
哪里?我的意思是它应该被初始化(在构造函数或ngOnInit中)'this.MyEnum = MyEnum.SOMETHING;',不是吗? – developer033