I had to pass the overlayRef manually, is there a nicer way to include it in the components constructor with DI?
service code:
display() {
const overlayRef = this.overlay.create({
positionStrategy: this.overlay.position().global().top(),
});
const portal = new ComponentPortal(ErrorsListBottomSheetComponent);
this.ref = overlayRef.attach<ErrorsListBottomSheetComponent>(portal);
this.ref.instance.overlayRef = overlayRef;
overlayRef.backdropClick().subscribe(() => {
overlayRef.detach();
});
}
component code:
export class ErrorsListBottomSheetComponent implements OnInit {
overlayRef: OverlayRef; -- REMOVE THIS--
constructor(
-- ADD SOMETHING HERE --
) {}
close() {
if (this.overlayRef) {
this.overlayRef.detach();
}
}
better yet, is there something for overlay similar to
<button mat-dialog-close>close</button>
instead of
<button (click)="close()">close</button>