【发布时间】:2021-06-23 14:34:55
【问题描述】:
我正在尝试使用枚举值更改模板。
TS:
enum NumType {
first, second, third
}
@Component({
selector: 'app-test',
template: `
<div [ngSwitch]="numType">
<a *ngSwitchCase="numType.first" href="first">first</a>
<a *ngSwitchCase="numType.second" href="second">second</a>
<a *ngSwitchCase="numType.third" href="third">third</a>
</div>
`,
})
export class TestElementComponent {
@Input() readonly numType: NumType;
}
HTML:
<app-test
[numType]="numType.first"
></app-info-element>
然后我得到了这个错误:
ERROR TypeError: Cannot read property 'first' of undefined
你能告诉我需要做什么才能让它工作吗?
使用 Angular 8。
【问题讨论】: