在控制器功能中未定义角度模板枚举

时间:2017-03-30 19:33:17

标签: angular

我在angular(4)app中有以下内容:

export enum RegisterAccomodationStatus {
    noFixedAbode = 1,
    sofaSurfing = 2,
    accommodation = 3,
    other = 4
}

在我的模板中,我有:

<button (click)="setCurrentAccomStatus(attendance, registerAccomodationStatus.noFixedAbode)" type="button" class="btn btn-default">NFA</button>
<button (click)="setCurrentAccomStatus(attendance, registerAccomodationStatus.sofaSurfing)" type="button" class="btn btn-default">Sofa</button>

我在我的组件中设置了一个属性:

registerAccomodationStatus: RegisterAccomodationStatus = RegisterAccomodationStatus.other;

最后我的功能:

setCurrentAccomStatus(registerAttendance: RegisterAttendance, accomStatusId: RegisterAccomodationStatus) {
        console.log(accomStatusId);
        registerAttendance.accomodationStatus = accomStatusId;

        this.registerService.updateGuestAttendance(registerAttendance)
            .subscribe(registerAtt => registerAttendance = registerAtt);
    }

点击其中一个按钮console.log(accomStatusId);正在提供undefined,但我按照我在网上找到的示例来执行此操作。

我做错了什么?

1 个答案:

答案 0 :(得分:8)

您应该定义以下属性:

registerAccomodationStatus = RegisterAccomodationStatus;

<强> Plunker Example