* Attaches the content with a particular context. * @docs-private
(context: any = {})
| 53 | * @docs-private |
| 54 | */ |
| 55 | attach(context: any = {}) { |
| 56 | if (!this._portal) { |
| 57 | this._portal = new TemplatePortal(this._template, this._viewContainerRef); |
| 58 | } |
| 59 | |
| 60 | this.detach(); |
| 61 | |
| 62 | if (!this._outlet) { |
| 63 | this._outlet = new DomPortalOutlet( |
| 64 | this._document.createElement('div'), |
| 65 | this._appRef, |
| 66 | this._injector, |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | const element: HTMLElement = this._template.elementRef.nativeElement; |
| 71 | |
| 72 | // Because we support opening the same menu from different triggers (which in turn have their |
| 73 | // own `OverlayRef` panel), we have to re-insert the host element every time, otherwise we |
| 74 | // risk it staying attached to a pane that's no longer in the DOM. |
| 75 | element.parentNode!.insertBefore(this._outlet.outletElement, element); |
| 76 | |
| 77 | // When `MatMenuContent` is used in an `OnPush` component, the insertion of the menu |
| 78 | // content via `createEmbeddedView` does not cause the content to be seen as "dirty" |
| 79 | // by Angular. This causes the `@ContentChildren` for menu items within the menu to |
| 80 | // not be updated by Angular. By explicitly marking for check here, we tell Angular that |
| 81 | // it needs to check for new menu items and update the `@ContentChild` in `MatMenu`. |
| 82 | this._changeDetectorRef.markForCheck(); |
| 83 | this._portal.attach(this._outlet, context); |
| 84 | this._attached.next(); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Detaches the content. |
nothing calls this directly
no test coverage detected