[英]Angular subscribe returns undefined object
所以我有材質對話框,在這個對話框中我有按鈕
<button mat-icon-button
(click)="getChoosenEmployee(element)">
</button>
元素是員工類型:
export interface Employee {
index: number;
employeeId: string;
firstName: string;
lastName: string;
}
當我關閉對話框時,我想將此員工發送到父組件,這就是我在做什么:
getChoosenEmployee(employee: Employee) {
this.dialogRef.close(
employee
);
}
在父組件中,我通過此函數接收
dialogRef.afterClosed().subscribe(result => {
console.log(this.choosenEmployee);
this.choosenEmployees.push(this.choosenEmployee);
});
推給我錯誤:
core.js:4197 ERROR TypeError: Cannot read property 'push' of undefined
at SafeSubscriber._next (add-workday-form.component.ts:72)
at SafeSubscriber.__tryOrUnsub (Subscriber.js:183)
at SafeSubscriber.next (Subscriber.js:122)
at Subscriber._next (Subscriber.js:72)
at Subscriber.next (Subscriber.js:49)
at Subject.next (Subject.js:39)
at SafeSubscriber._next (dialog.js:381)
at SafeSubscriber.__tryOrUnsub (Subscriber.js:183)
at SafeSubscriber.next (Subscriber.js:122)
at Subscriber._next (Subscriber.js:72)
您是否初始化了this.choosenEmployees
數組? 該錯誤表明this.choosenEmployees
未定義,而不是this.choosenEmployee
對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.