1
所以我得到控制檯錯誤Cannot set property 'stepModels' of undefined
,但typescript編譯罰款。我在這裏做錯了什麼?我似乎無法弄清楚。任何幫助深表感謝。'應用綁定時無法設置未定義的屬性'錯誤
class ViewModel {
public index: number;
public percentage: number;
public getTemplate: any;
public goNext: any;
public goPrevious: any;
public stepModels: KnockoutObservable<Array<Step>>;
public currentStep: KnockoutObservable<Step>;
public currentIndex: KnockoutComputed<number>;
public currentPercentage: KnockoutComputed<number>;
public canGoNext: KnockoutComputed<boolean>;
public canGoPrevious: KnockoutComputed<boolean>;
constructor() {
let self = this;
self.stepModels = ko.observableArray([
new Step(1, 'emailTmpl'),
new Step(2, 'usernameTmpl'),
new Step(3, 'passwordTmpl'),
new Step(4, 'questionsMainTmpl'),
new Step(5, 'questionsTmpl'),
new Step(6, 'questionsFinalTmpl'),
new Step(7, 'verifyTmpl'),
new Step(8, 'successTmpl')
]);
}
}
然後:
ko.applyBindings(ViewModel, element);
看來你並沒有初始化'stepModels'屬性。 –
你如何實例化這個視圖模型? – Alex
@Alex'ko.applyBindings(ViewModel,element);' –