我试图在angularjs 2模板中使用enum.
@Component({
selector: 'test',
template: `
<ul class="nav navbar-nav">
<li class="{{activeSection == SectionType.Primary ? 'active': ''}}"><a href="javscript:void(0);" (click)="setActiveSection(SectionType.Primary)">Primary Details</a></li>
<li class="{{activeSection == SectionType.Aditional ? 'active': ''}}"><a href="javscript:void(0);" (click)="setActiveSection(SectionType.Aditional)">Additional Details</a></li>
<li class="{{activeSection == SectionType.Payment ? 'active': ''}}"><a href="javscript:void(0);" (click)="setActiveSection(SectionType.Payment)">Payment Settings </a></li>
</ul>`
})
export class TestComponent{
activeSection: SectionType = SectionType.Primary;
setActiveSection(section: SectionType) {
this.activeSection = section;
}
}
以下是我的列举:
enum SectionType {
Primary,
Aditional,
Payment
}
引发异常:TypeError:无法读取未定义的属性""Primary""