Regarding closing a dialog. https://material.angular.io/components/component/dialog afterClosed
is not thenable?
As in official main documentation:
Property 'then' does not exist on type '() => Observable<any>'. [default] Checking finished with 1 errors
I tried subscribe, but doesnt work either.
You can pass any kind of data to the component by adding data to the MatDialog's open() options. }, }); You can retrieve the data by injecting MAT_DIALOG_DATA in the opened component.
You can test Angular Material Dialog's afterClosed method this way: import { of } from 'rxjs'; spy on the dialog and return an observable for the afterClosed() method.
NO you don't need to unsubscribe, as it automatically completes.
MatDialog creates modal dialogs that implements the ARIA role="dialog" pattern by default. You can change the dialog's role to alertdialog via MatDialogConfig . You should provide an accessible label to this root dialog element by setting the ariaLabel or ariaLabelledBy properties of MatDialogConfig .
No need to unsubscribe from afterClosed()
as it auto completes itself:
https://github.com/angular/material2/blob/ae41a0ad69ca26c600f0f56c68dd5a1c102d4f1f/src/lib/dialog/dialog-ref.ts#L75
Based on the examples part of their documentation
let dialogRef = this.dialog.open(DialogResultExampleDialog);
dialogRef.afterClosed().subscribe(result => {
this.selectedOption = result;
});
But you always can convert result to promise if needed
dialogRef.afterClosed().toPromise()
Do not forget to add toPromise
support
import "rxjs/add/operator/toPromise";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With