Skip to content

feat(dialog): allow for custom ComponentFactoryResolver to be passed in #16437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2019
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
5 changes: 4 additions & 1 deletion src/material/dialog/dialog-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {ViewContainerRef} from '@angular/core';
import {ViewContainerRef, ComponentFactoryResolver} from '@angular/core';
import {Direction} from '@angular/cdk/bidi';
import {ScrollStrategy} from '@angular/cdk/overlay';

Expand Down Expand Up @@ -114,5 +114,8 @@ export class MatDialogConfig<D = any> {
*/
closeOnNavigation?: boolean = true;

/** Alternate `ComponentFactoryResolver` to use when resolving the associated component. */
componentFactoryResolver?: ComponentFactoryResolver;

// TODO(jelbourn): add configuration for lifecycle hooks, ARIA labelling.
}
16 changes: 15 additions & 1 deletion src/material/dialog/dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
NgModule,
TemplateRef,
ViewChild,
ViewContainerRef
ViewContainerRef,
ComponentFactoryResolver
} from '@angular/core';
import {By} from '@angular/platform-browser';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
Expand Down Expand Up @@ -741,6 +742,19 @@ describe('MatDialog', () => {
expect(scrollStrategy.enable).toHaveBeenCalled();
}));

it('should be able to pass in an alternate ComponentFactoryResolver',
inject([ComponentFactoryResolver], (resolver: ComponentFactoryResolver) => {
spyOn(resolver, 'resolveComponentFactory').and.callThrough();

dialog.open(PizzaMsg, {
viewContainerRef: testViewContainerRef,
componentFactoryResolver: resolver
});
viewContainerFixture.detectChanges();

expect(resolver.resolveComponentFactory).toHaveBeenCalled();
}));

describe('passing in data', () => {
it('should be able to pass in data', () => {
let config = {
Expand Down
4 changes: 2 additions & 2 deletions src/material/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ export class MatDialog implements OnDestroy {
const injector = new PortalInjector(userInjector || this._injector, new WeakMap([
[MatDialogConfig, config]
]));
const containerPortal =
new ComponentPortal(MatDialogContainer, config.viewContainerRef, injector);
const containerPortal = new ComponentPortal(MatDialogContainer,
config.viewContainerRef, injector, config.componentFactoryResolver);
const containerRef = overlay.attach<MatDialogContainer>(containerPortal);

return containerRef.instance;
Expand Down
1 change: 1 addition & 0 deletions tools/public_api_guard/material/dialog.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export declare class MatDialogConfig<D = any> {
autoFocus?: boolean;
backdropClass?: string;
closeOnNavigation?: boolean;
componentFactoryResolver?: ComponentFactoryResolver;
data?: D | null;
direction?: Direction;
disableClose?: boolean;
Expand Down