onClickGetDates(appt) { this.dialogService .confirmDateRange('Get Dates', 'Enter two dates:', appt.beginDate, appt.endDate) .subscribe(res => this.dateRange = res); . . // I would like to now save the dateRange result to my database, but at this point, result is [null,null], so the code below does nothing (except null out the dates): appt.beginDate = dateRange[0]; appt.endDate = dateRange[1]; this.apptdata.updateAppt(appt); }
onClickGetDates(appt) { this.dialogService .confirmDateRange('Get Dates', 'Enter two dates:', appt.beginDate, appt.endDate) .subscribe(res => {this.dateRange = res; //Set the appt's properties inside the subscribe appt.beginDate = this.dateRange[0]; appt.endDate = this.dateRange[1]; this.apptdata.updateAppt(appt); });
另一答案
Use @Output() to send dates from inner component to outer component and implement a function that call on Ok button and emit that data from that function like : `@Output() respOnse= new EventEmitter(); onOkClicked() { this.response.next({beginDate : beginDate , endDate: endDate}); this.dialogRef.close(); } onCancelClicked() { this.dialogRef.close(); } confirmDateRange(title: string, message: string,appt): Observable { let dialogRef: MatDialogRef; dialogRef = this.dialog.open(ConfirmDialogComponent); dialogRef.componentInstance.title = title; dialogRef.componentInstance.message = message; dialogRef.componentInstance.beginDate = appt.begin; dialogRef.componentInstance.endDate = appt.end; dialogRef.componentInstance.response.subscribe(res : any => { appt.begin = res.beginDate; appt.end = res.endDate; }); } onClickGetDates(title:string , message :string , appt) { this.confirmDateRange(title,message,appt); } `