Skip to content
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

[Modal] allow user's define injector #4710

Closed
tieppt opened this issue Jan 21, 2020 · 1 comment
Closed

[Modal] allow user's define injector #4710

tieppt opened this issue Jan 21, 2020 · 1 comment
Assignees
Labels

Comments

@tieppt
Copy link

tieppt commented Jan 21, 2020

What problem does this feature solve?

When using modal, you're using ViewContainerRef from constructor injection to create child injector, which lead to an issue: the component we want to dynamic rendering (may request service provided by any level of injector tree), can not get right services.

Stackblitz: https://stackblitz.com/edit/angular-jdeqhr?file=src/app/app.component.ts

What does the proposed API look like?

User can send an instance of ViewContainerRef (this is optional) as Material Dialog approach.

private _createInjector<T>(
      config: MatDialogConfig,
      dialogRef: MatDialogRef<T>,
      dialogContainer: MatDialogContainer): PortalInjector {

    const userInjector = config && config.viewContainerRef && config.viewContainerRef.injector;

    // The MatDialogContainer is injected in the portal as the MatDialogContainer and the dialog's
    // content are created out of the same ViewContainerRef and as such, are siblings for injector
    // purposes. To allow the hierarchy that is expected, the MatDialogContainer is explicitly
    // added to the injection tokens.
    const injectionTokens = new WeakMap<any, any>([
      [MatDialogContainer, dialogContainer],
      [MAT_DIALOG_DATA, config.data],
      [MatDialogRef, dialogRef]
    ]);

    if (config.direction &&
        (!userInjector || !userInjector.get<Directionality | null>(Directionality, null))) {
      injectionTokens.set(Directionality, {
        value: config.direction,
        change: observableOf()
      });
    }

    return new PortalInjector(userInjector || this._injector, injectionTokens);
  }
hsuanxyz added a commit to hsuanxyz/ng-zorro-antd that referenced this issue Feb 4, 2020
@hsuanxyz hsuanxyz added the 👨‍🏭 Some one working on this A community member has started working on this label Feb 4, 2020
hsuanxyz added a commit to hsuanxyz/ng-zorro-antd that referenced this issue Feb 10, 2020
close NG-ZORRO#4710

test(module:modal): add footer directive test

test(module:modal): add callback test

test(module:modal): add animation test

test(module:modal): add classname and styles test

test(module:modal): add footer component test

test(module:modal): fix test

test(module:modal): fix test

test(module:modal): add confirm test

test(module:modal): fix test

test(module:modal): add component mode test

chore: remove console

test: fix ci test
Ricbet pushed a commit to Ricbet/ng-zorro-antd that referenced this issue Apr 9, 2020
* refactor(module:modal): refactor the modal service

close NG-ZORRO#3652, close NG-ZORRO#4437, close NG-ZORRO#2749

* feat(module:modal): support autofocus

close NG-ZORRO#3423, close NG-ZORRO#4126

* refactor(module:modal): refactor the modal component

* chore: rename files

* test(module:modal): add test case

* test(module:modal): add test case

* feat(module:modal): support nzCloseOnNavigation

* feat(module:modal): support nzViewContainerRef

close NG-ZORRO#4710

test(module:modal): add footer directive test

test(module:modal): add callback test

test(module:modal): add animation test

test(module:modal): add classname and styles test

test(module:modal): add footer component test

test(module:modal): fix test

test(module:modal): fix test

test(module:modal): add confirm test

test(module:modal): fix test

test(module:modal): add component mode test

chore: remove console

test: fix ci test
hsuanxyz added a commit to hsuanxyz/ng-zorro-antd that referenced this issue Aug 5, 2020
* refactor(module:modal): refactor the modal service

close NG-ZORRO#3652, close NG-ZORRO#4437, close NG-ZORRO#2749

* feat(module:modal): support autofocus

close NG-ZORRO#3423, close NG-ZORRO#4126

* refactor(module:modal): refactor the modal component

* chore: rename files

* test(module:modal): add test case

* test(module:modal): add test case

* feat(module:modal): support nzCloseOnNavigation

* feat(module:modal): support nzViewContainerRef

close NG-ZORRO#4710

test(module:modal): add footer directive test

test(module:modal): add callback test

test(module:modal): add animation test

test(module:modal): add classname and styles test

test(module:modal): add footer component test

test(module:modal): fix test

test(module:modal): fix test

test(module:modal): add confirm test

test(module:modal): fix test

test(module:modal): add component mode test

chore: remove console

test: fix ci test
@marct83
Copy link

marct83 commented Oct 1, 2020

Did this go into V10? I'm still seeing my modal components not inheriting Providers from parent component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants