Type safe dialog afterClosed()
See original GitHub issueBug, feature request, or proposal:
feature request
What is the expected behavior?
MatDialogRef.afterClosed()
return Observable
of a type other than any
.
What is the current behavior?
MatDialogRef.afterClosed()
returns Observable<any>
.
What is the use-case or motivation for changing an existing behavior?
type safety
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
all
Is there anything else we should know?
I tried:
export interface DialogComponent<R> { }
export interface TypedMatDialogRef<T extends DialogComponent<R>, R> extends MatDialogRef<T> {
afterClosed(): Observable<R>;
}
export interface TypedMatDialog extends MatDialog {
open<T extends DialogComponent<R>, R, D = any>(componentOrTemplateRef: ComponentType<T>, config?: MatDialogConfig<D>): TypedMatDialogRef<T, R>;
}
@Component({})
export class MyDialogComponent implements DialogComponent<string> { }
(this.dialog as TypedMatDialog).open(MyDialogComponent)
.afterClosed()
.subscribe(string => {/* string is showing as {}*/});
Not sure why this doesn’t work.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to subscribe to angularMaterial Dialog afterClosed?
No need to unsubscribe from afterClosed() as it auto completes itself: ...
Read more >Angular Material Dialog: A Complete Example
In this post, we are going to go through a complete example of how to build a custom dialog using the Angular Material...
Read more >Dialog | Angular Material
The MatDialog service can be used to open modal dialogs with Material Design styling and ... afterClosed().subscribe(result => { console.log(`Dialog result: ...
Read more >How can I unit test dialogRef.afterClosed() using Jest? - Reddit
My test configuration file is : TestBed.configureTestingModule({ declarations: [OptionTableComponent, WhoComponent, PropertiesComponent], ...
Read more >mat-dialog-close not working - You.com | The AI Search ...
<button type="submit" (click)="addUser()" mat-dialog-close ... After inserting data on clicking save the HTTP POST service gets called and data gets ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here’s a quick example of defining the result type: https://stackblitz.com/edit/angular-iw4975?file=app/dialog-overview-example.ts
Note that result is typed as string via
let dialogRef: MatDialogRef<DialogOverviewExampleDialog, string>
If you try changing it to
number
, you’ll see an error show up when you try to assignresult
toanimal
which demonstrates that it is typing correctly.Will there be an example of how to utilize?