Skip to content

CdkPortalOutlet hasAttached not called when using attachComponentPortal #8628

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

Closed
probert94 opened this issue Nov 24, 2017 · 1 comment · Fixed by #8642
Closed

CdkPortalOutlet hasAttached not called when using attachComponentPortal #8628

probert94 opened this issue Nov 24, 2017 · 1 comment · Fixed by #8642
Assignees
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@probert94
Copy link

Bug, feature request, or proposal:

Bug report

What is the expected behavior?

When I attach a Component or a Template to a CdkPortalOutlet using attachComponentPortal or attachTemplatePortal, I expect that hasAttached returns true.

What is the current behavior?

hasAttached always returns false, except, when using the cdkPortalOutlet-input t oset the portal.

What are the steps to reproduce?

  1. Create a Component, which contains a cdkPortalOutlet.
  2. Get a reference to the CdkPortalOutlet-Directive using @ViewChild(CdkPortalOutlet).
  3. Attach a Template to it, using attachTemplatePortal.
  4. Call hasAttached() which should return false.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

I am using Angular Material+CDK version 5.0.0-rc.1 as awell as Angular version 5.0.3

Is there anything else we should know?

The problem is in portal-directives.ts#L114 and portal-directives.ts#L129, where this._portal = portal should probably be this.portal = portal, so that the setter is called and updates the _attachedPortal of the super-class.

@crisbeto crisbeto self-assigned this Nov 24, 2017
@crisbeto crisbeto added has pr P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Nov 25, 2017
crisbeto added a commit to crisbeto/material2 that referenced this issue Nov 25, 2017
… attached too early

Fixes the `hasAttached` method always returning false when the portal was attached using `CdkPortalOutlet.attachComponentPortal` or `CdkPortalOutlet.attachTemplatePortal`. This means that checks like https://github.com/angular/material2/blob/master/src/lib/dialog/dialog-container.ts#L118 always evaluate to false.

Fixing `hasAttached` revealed another issue: if a portal outlet is unbound (e.g. `<div cdkPortalOutlet>`) and the consumer attaches something to it on the first CD round, the content will be cleared immediately due to Angular invoking the getter with an empty string. This has been fixed by ignoring strings altogether since the portal outlet can't do anything with them anyway and they don't match the type signature.

Fixes angular#8628.
crisbeto added a commit to crisbeto/material2 that referenced this issue Nov 25, 2017
… attached too early

Fixes the `hasAttached` method always returning false when the portal was attached using `CdkPortalOutlet.attachComponentPortal` or `CdkPortalOutlet.attachTemplatePortal`. This means that checks like https://github.com/angular/material2/blob/master/src/lib/dialog/dialog-container.ts#L118 always evaluate to false.

Fixing `hasAttached` revealed another issue: if a portal outlet is unbound (e.g. `<div cdkPortalOutlet>`) and the consumer attaches something to it on the before the first CD round, the content will be cleared immediately due to Angular invoking the getter with an empty string. This has been fixed by not clearing any previously-attached portals if the reset value is set before `ngOnInit`.

Fixes angular#8628.
crisbeto added a commit to crisbeto/material2 that referenced this issue Nov 27, 2017
… attached too early

Fixes the `hasAttached` method always returning false when the portal was attached using `CdkPortalOutlet.attachComponentPortal` or `CdkPortalOutlet.attachTemplatePortal`. This means that checks like https://github.com/angular/material2/blob/master/src/lib/dialog/dialog-container.ts#L118 always evaluate to false.

Fixing `hasAttached` revealed another issue: if a portal outlet is unbound (e.g. `<div cdkPortalOutlet>`) and the consumer attaches something to it on the before the first CD round, the content will be cleared immediately due to Angular invoking the getter with an empty string. This has been fixed by not clearing any previously-attached portals if the reset value is set before `ngOnInit`.

Fixes angular#8628.
mmalerba pushed a commit that referenced this issue Dec 8, 2017
… attached too early (#8642)

Fixes the `hasAttached` method always returning false when the portal was attached using `CdkPortalOutlet.attachComponentPortal` or `CdkPortalOutlet.attachTemplatePortal`. This means that checks like https://github.com/angular/material2/blob/master/src/lib/dialog/dialog-container.ts#L118 always evaluate to false.

Fixing `hasAttached` revealed another issue: if a portal outlet is unbound (e.g. `<div cdkPortalOutlet>`) and the consumer attaches something to it on the before the first CD round, the content will be cleared immediately due to Angular invoking the getter with an empty string. This has been fixed by not clearing any previously-attached portals if the reset value is set before `ngOnInit`.

Fixes #8628.
mmalerba pushed a commit that referenced this issue Dec 8, 2017
… attached too early (#8642)

Fixes the `hasAttached` method always returning false when the portal was attached using `CdkPortalOutlet.attachComponentPortal` or `CdkPortalOutlet.attachTemplatePortal`. This means that checks like https://github.com/angular/material2/blob/master/src/lib/dialog/dialog-container.ts#L118 always evaluate to false.

Fixing `hasAttached` revealed another issue: if a portal outlet is unbound (e.g. `<div cdkPortalOutlet>`) and the consumer attaches something to it on the before the first CD round, the content will be cleared immediately due to Angular invoking the getter with an empty string. This has been fixed by not clearing any previously-attached portals if the reset value is set before `ngOnInit`.

Fixes #8628.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
2 participants