所以我有一个材料对话框,在这个对话框中我有一个按钮
<button mat-icon-button
(click)="getChoosenEmployee(element)">
</button>
元素是Employee类型:
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)
答案 0 :(得分:2)
您是否初始化了gcloud compute ssh --zone=us-central1-a ${user}@${instance_name_arg}
数组?该错误表明未定义this.choosenEmployees
对象,而不是this.choosenEmployees
对象。