Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/material/dialog/dialog.spec.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,6 +31,7 @@ import {
inject,
inputBinding,
} from '@angular/core';
import {DialogRef} from '@angular/cdk/dialog';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {Subject} from 'rxjs';
Expand DownExpand Up@@ -873,6 +874,14 @@ describe('MatDialog', () => {
expect(pane.classList).not.toContain('custom-class-one', 'Expected class to be removed');
});

it('should not inject the CDK dialog ref into the child component', () => {
const dialogRef = dialog.open(PizzaMsg, {viewContainerRef: testViewContainerRef});
viewContainerFixture.detectChanges();

expect(dialogRef.componentInstance.cdkDialogRef).toBe(null);
expect(dialogRef.componentInstance.dialogRef).toBeTruthy();
});

describe('disableClose option', () => {
it('should prevent closing via clicks on the backdrop', async () => {
dialog.open(PizzaMsg, {disableClose: true, viewContainerRef: testViewContainerRef});
Expand DownExpand Up@@ -2372,6 +2381,7 @@ class PizzaMsg {
dialogRef = inject<MatDialogRef<PizzaMsg>>(MatDialogRef);
dialogInjector = inject(Injector);
directionality = inject(Directionality);
cdkDialogRef = inject(DialogRef, {optional: true});
}

@Component({
Expand Down
3 changes: 2 additions & 1 deletion src/material/dialog/dialog.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,7 @@ import {MatDialogConfig} from './dialog-config';
import {MatDialogContainer} from './dialog-container';
import {MatDialogRef} from './dialog-ref';
import {defer, Observable, Subject} from 'rxjs';
import {Dialog, DialogConfig} from '@angular/cdk/dialog';
import {Dialog, DialogConfig, DialogRef} from '@angular/cdk/dialog';
import {startWith} from 'rxjs/operators';
import {_IdGenerator} from '@angular/cdk/a11y';
import {_animationsDisabled} from '../core';
Expand DownExpand Up@@ -178,6 +178,7 @@ export class MatDialog implements OnDestroy {
{provide: this._dialogContainerType, useValue: dialogContainer},
{provide: this._dialogDataToken, useValue: cdkConfig.data},
{provide: this._dialogRefConstructor, useValue: dialogRef},
{provide: DialogRef, useValue: null},
];
},
});
Expand Down
Loading