在ngIf中使用枚举类型时,需要在组件或模块的ts文件中引用枚举类型,如下所示:
export enum EnumType { Type1 = 'Type1', Type2 = 'Type2' }
@Component({ selector: 'app-component', templateUrl: './app.component.html' }) export class AppComponent { enumType = EnumType; // 引用枚举类型 showType1 = true; }
然后在模板文件中使用枚举类型时,需要使用引用的枚举类型,如下所示: