如何在Angular 8模板中使用枚举?
组成部分ts
import { Component } from '@angular/core';
import { SomeEnum } from './global';
@Component({
selector: 'my-app',
templateUrl: './app.组成部分html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = SomeEnum.someValue;
}
组成部分html
<span *ngIf="name === SomeEnum.someValue">This has some value</value>
这目前不起作用,因为模板没有对SomeEnum
的引用.我该怎么解决呢?
ERROR Error: Cannot read property 'someValue' of undefined