如何在Angular 8模板中使用枚举?
component.ts
import { Component } from '@angular/core';
import { SomeEnum } from './global';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = SomeEnum.someValue;
}
component.html
<span *ngIf="name === SomeEnum.someValue">This has some value</value>
目前无法使用,因为模板没有引用SomeEnum
。我该如何解决?
ERROR Error: Cannot read property 'someValue' of undefined
在TS中
public get SomeEnum() {
return SomeEnum;
}
在HTML中使用
*ngIf="SomeEnum.someValue === 'abc'"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句