Angular CDK Overlay, change default overlay containerHow to change an element's class with JavaScript?Set a default parameter value for a JavaScript functionDetermine whether an array contains a valueHow to extend an existing JavaScript array with another array, without creating a new arrayHow to check whether a string contains a substring in JavaScript?animate angular cdk overlayGet active position on angular cdk overlay?Angular CDK: Overlay and Change DetectionAngular CDK connect overlay with scroll to containerCustom parent container for Angular material overlay container?
How to find if SQL server backup is encrypted with TDE without restoring the backup
Can compressed videos be decoded back to their uncompresed original format?
How can I deal with my CEO asking me to hire someone with a higher salary than me, a co-founder?
Rotate ASCII Art by 45 Degrees
How to travel to Japan while expressing milk?
What exactly is ineptocracy?
Why are UK visa biometrics appointments suspended at USCIS Application Support Centers?
files created then deleted at every second in tmp directory
How to Prove P(a) → ∀x(P(x) ∨ ¬(x = a)) using Natural Deduction
OP Amp not amplifying audio signal
How to remove border from elements in the last row?
How to install cross-compiler on Ubuntu 18.04?
Knowledge-based authentication using Domain-driven Design in C#
Why was Sir Cadogan fired?
Could the museum Saturn V's be refitted for one more flight?
Is this draw by repetition?
Forgetting the musical notes while performing in concert
Getting extremely large arrows with tikzcd
How to show a landlord what we have in savings?
my venezuela girlfriend wants to travel the USA where i live.what does she need to do and how expensive will it become or how difficult?
Why didn't Boeing produce its own regional jet?
Do creatures with a listed speed of "0 ft., fly 30 ft. (hover)" ever touch the ground?
ssTTsSTtRrriinInnnnNNNIiinngg
What reasons are there for a Capitalist to oppose a 100% inheritance tax?
Angular CDK Overlay, change default overlay container
How to change an element's class with JavaScript?Set a default parameter value for a JavaScript functionDetermine whether an array contains a valueHow to extend an existing JavaScript array with another array, without creating a new arrayHow to check whether a string contains a substring in JavaScript?animate angular cdk overlayGet active position on angular cdk overlay?Angular CDK: Overlay and Change DetectionAngular CDK connect overlay with scroll to containerCustom parent container for Angular material overlay container?
Is there a way to change the OverlayContainer?
I have created a tooltip component, but sometimes I want to attach the overlay to a specific element (by default the overlay is attached to the document body).
Here is how I am creating the overlay:
private initOverlay(): void
const positionStrategy = this.overlayPositionBuilder
.flexibleConnectedTo(this.elementRef)
.withPositions([this.resolvedConfig]);
this.overlayRef = this.overlay.create(positionStrategy);
And this is how I am attaching a template to it:
show(): void
this.overlayRef.attach(new TemplatePortal(this.tpl, this.viewContainerRef));
javascript angular angular-material cdk
add a comment |
Is there a way to change the OverlayContainer?
I have created a tooltip component, but sometimes I want to attach the overlay to a specific element (by default the overlay is attached to the document body).
Here is how I am creating the overlay:
private initOverlay(): void
const positionStrategy = this.overlayPositionBuilder
.flexibleConnectedTo(this.elementRef)
.withPositions([this.resolvedConfig]);
this.overlayRef = this.overlay.create(positionStrategy);
And this is how I am attaching a template to it:
show(): void
this.overlayRef.attach(new TemplatePortal(this.tpl, this.viewContainerRef));
javascript angular angular-material cdk
What's your use case for attaching it to a specific element?
– adamdport
Mar 21 at 20:38
I have a dialog, the tooltip appears behind it (the tooltip trigger is placed on the dialog).
– vlio20
Mar 21 at 20:40
add a comment |
Is there a way to change the OverlayContainer?
I have created a tooltip component, but sometimes I want to attach the overlay to a specific element (by default the overlay is attached to the document body).
Here is how I am creating the overlay:
private initOverlay(): void
const positionStrategy = this.overlayPositionBuilder
.flexibleConnectedTo(this.elementRef)
.withPositions([this.resolvedConfig]);
this.overlayRef = this.overlay.create(positionStrategy);
And this is how I am attaching a template to it:
show(): void
this.overlayRef.attach(new TemplatePortal(this.tpl, this.viewContainerRef));
javascript angular angular-material cdk
Is there a way to change the OverlayContainer?
I have created a tooltip component, but sometimes I want to attach the overlay to a specific element (by default the overlay is attached to the document body).
Here is how I am creating the overlay:
private initOverlay(): void
const positionStrategy = this.overlayPositionBuilder
.flexibleConnectedTo(this.elementRef)
.withPositions([this.resolvedConfig]);
this.overlayRef = this.overlay.create(positionStrategy);
And this is how I am attaching a template to it:
show(): void
this.overlayRef.attach(new TemplatePortal(this.tpl, this.viewContainerRef));
javascript angular angular-material cdk
javascript angular angular-material cdk
edited Mar 21 at 20:33
vlio20
asked Mar 21 at 20:10
vlio20vlio20
4,4131374145
4,4131374145
What's your use case for attaching it to a specific element?
– adamdport
Mar 21 at 20:38
I have a dialog, the tooltip appears behind it (the tooltip trigger is placed on the dialog).
– vlio20
Mar 21 at 20:40
add a comment |
What's your use case for attaching it to a specific element?
– adamdport
Mar 21 at 20:38
I have a dialog, the tooltip appears behind it (the tooltip trigger is placed on the dialog).
– vlio20
Mar 21 at 20:40
What's your use case for attaching it to a specific element?
– adamdport
Mar 21 at 20:38
What's your use case for attaching it to a specific element?
– adamdport
Mar 21 at 20:38
I have a dialog, the tooltip appears behind it (the tooltip trigger is placed on the dialog).
– vlio20
Mar 21 at 20:40
I have a dialog, the tooltip appears behind it (the tooltip trigger is placed on the dialog).
– vlio20
Mar 21 at 20:40
add a comment |
1 Answer
1
active
oldest
votes
Please reference this stackblitz example.
looks like you can accomplish this by extending the
OverlayContainer
class via the following inapp.module.ts
provide: OverlayContainer, useFactory: () => new AppOverlayContainer()
Stackblitz
https://stackblitz.com/edit/angular-material2-issue-ansnt5?file=app%2Fapp.module.ts
This GitHub comment also provides an example of how to package this in a directive
GitHub comment
https://github.com/angular/material2/issues/7349#issuecomment-337513040
Revision 3/22/19 working directive example
Extend the OverlayContainer
class via cdk-overlay-container.ts
Stub the class in app.module.ts
providers: [
provide: OverlayContainer, useClass: CdkOverlayContainer ,
]
In your cdk-overlay-container.ts
you are preventing the default _createContainer()
from working, and providing your own custom public method myCreateContainer
to replace it.
You are essentially creating an empty
div
here, adding a custom class to itmy-custom-overlay-container-class
and appending it to the
div
the directive is attached to, then passing that container to the
private variable_containerElement
in the trueOverlayContainer
class.
/**
* Create overlay container and append to ElementRef from directive
*/
public myCreateContainer(element: HTMLElement): void
let container = document.createElement('div');
container.classList.add('my-custom-overlay-container-class');
element.appendChild(container);
this._containerElement = container;
/**
* Prevent creation of the HTML element, use custom method above
*/
protected _createContainer(): void
return;
Then in your cdk-overlay-container.directive.ts
your are calling myCreateContainer()
and passing the ElementRef
as an argument.
this.cdkOverlayContainer['myCreateContainer'](this.elementReference.nativeElement);
Then in your HTML assign the directive where you want it to show up.
<div myCdkOverlayContainer
Stackblitz
https://stackblitz.com/edit/angular-material2-issue-6nzwws?embed=1&file=app/app.component.html
Yes, I saw this suggestion, the problem with this is that I might need to provide the custom OverlayContainer per each instance of the tooltip directive. Seems though there is no other way to achieve this. Would be nice if it would be configurable though.
– vlio20
Mar 21 at 21:20
Although I believe the directive approach may be a solution here, I am having trouble implementing it in stackblitz. Will update answer if I can get it going.
– Marshal
Mar 21 at 22:28
Please see revision with directive example.
– Marshal
Mar 22 at 15:50
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288559%2fangular-cdk-overlay-change-default-overlay-container%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Please reference this stackblitz example.
looks like you can accomplish this by extending the
OverlayContainer
class via the following inapp.module.ts
provide: OverlayContainer, useFactory: () => new AppOverlayContainer()
Stackblitz
https://stackblitz.com/edit/angular-material2-issue-ansnt5?file=app%2Fapp.module.ts
This GitHub comment also provides an example of how to package this in a directive
GitHub comment
https://github.com/angular/material2/issues/7349#issuecomment-337513040
Revision 3/22/19 working directive example
Extend the OverlayContainer
class via cdk-overlay-container.ts
Stub the class in app.module.ts
providers: [
provide: OverlayContainer, useClass: CdkOverlayContainer ,
]
In your cdk-overlay-container.ts
you are preventing the default _createContainer()
from working, and providing your own custom public method myCreateContainer
to replace it.
You are essentially creating an empty
div
here, adding a custom class to itmy-custom-overlay-container-class
and appending it to the
div
the directive is attached to, then passing that container to the
private variable_containerElement
in the trueOverlayContainer
class.
/**
* Create overlay container and append to ElementRef from directive
*/
public myCreateContainer(element: HTMLElement): void
let container = document.createElement('div');
container.classList.add('my-custom-overlay-container-class');
element.appendChild(container);
this._containerElement = container;
/**
* Prevent creation of the HTML element, use custom method above
*/
protected _createContainer(): void
return;
Then in your cdk-overlay-container.directive.ts
your are calling myCreateContainer()
and passing the ElementRef
as an argument.
this.cdkOverlayContainer['myCreateContainer'](this.elementReference.nativeElement);
Then in your HTML assign the directive where you want it to show up.
<div myCdkOverlayContainer
Stackblitz
https://stackblitz.com/edit/angular-material2-issue-6nzwws?embed=1&file=app/app.component.html
Yes, I saw this suggestion, the problem with this is that I might need to provide the custom OverlayContainer per each instance of the tooltip directive. Seems though there is no other way to achieve this. Would be nice if it would be configurable though.
– vlio20
Mar 21 at 21:20
Although I believe the directive approach may be a solution here, I am having trouble implementing it in stackblitz. Will update answer if I can get it going.
– Marshal
Mar 21 at 22:28
Please see revision with directive example.
– Marshal
Mar 22 at 15:50
add a comment |
Please reference this stackblitz example.
looks like you can accomplish this by extending the
OverlayContainer
class via the following inapp.module.ts
provide: OverlayContainer, useFactory: () => new AppOverlayContainer()
Stackblitz
https://stackblitz.com/edit/angular-material2-issue-ansnt5?file=app%2Fapp.module.ts
This GitHub comment also provides an example of how to package this in a directive
GitHub comment
https://github.com/angular/material2/issues/7349#issuecomment-337513040
Revision 3/22/19 working directive example
Extend the OverlayContainer
class via cdk-overlay-container.ts
Stub the class in app.module.ts
providers: [
provide: OverlayContainer, useClass: CdkOverlayContainer ,
]
In your cdk-overlay-container.ts
you are preventing the default _createContainer()
from working, and providing your own custom public method myCreateContainer
to replace it.
You are essentially creating an empty
div
here, adding a custom class to itmy-custom-overlay-container-class
and appending it to the
div
the directive is attached to, then passing that container to the
private variable_containerElement
in the trueOverlayContainer
class.
/**
* Create overlay container and append to ElementRef from directive
*/
public myCreateContainer(element: HTMLElement): void
let container = document.createElement('div');
container.classList.add('my-custom-overlay-container-class');
element.appendChild(container);
this._containerElement = container;
/**
* Prevent creation of the HTML element, use custom method above
*/
protected _createContainer(): void
return;
Then in your cdk-overlay-container.directive.ts
your are calling myCreateContainer()
and passing the ElementRef
as an argument.
this.cdkOverlayContainer['myCreateContainer'](this.elementReference.nativeElement);
Then in your HTML assign the directive where you want it to show up.
<div myCdkOverlayContainer
Stackblitz
https://stackblitz.com/edit/angular-material2-issue-6nzwws?embed=1&file=app/app.component.html
Yes, I saw this suggestion, the problem with this is that I might need to provide the custom OverlayContainer per each instance of the tooltip directive. Seems though there is no other way to achieve this. Would be nice if it would be configurable though.
– vlio20
Mar 21 at 21:20
Although I believe the directive approach may be a solution here, I am having trouble implementing it in stackblitz. Will update answer if I can get it going.
– Marshal
Mar 21 at 22:28
Please see revision with directive example.
– Marshal
Mar 22 at 15:50
add a comment |
Please reference this stackblitz example.
looks like you can accomplish this by extending the
OverlayContainer
class via the following inapp.module.ts
provide: OverlayContainer, useFactory: () => new AppOverlayContainer()
Stackblitz
https://stackblitz.com/edit/angular-material2-issue-ansnt5?file=app%2Fapp.module.ts
This GitHub comment also provides an example of how to package this in a directive
GitHub comment
https://github.com/angular/material2/issues/7349#issuecomment-337513040
Revision 3/22/19 working directive example
Extend the OverlayContainer
class via cdk-overlay-container.ts
Stub the class in app.module.ts
providers: [
provide: OverlayContainer, useClass: CdkOverlayContainer ,
]
In your cdk-overlay-container.ts
you are preventing the default _createContainer()
from working, and providing your own custom public method myCreateContainer
to replace it.
You are essentially creating an empty
div
here, adding a custom class to itmy-custom-overlay-container-class
and appending it to the
div
the directive is attached to, then passing that container to the
private variable_containerElement
in the trueOverlayContainer
class.
/**
* Create overlay container and append to ElementRef from directive
*/
public myCreateContainer(element: HTMLElement): void
let container = document.createElement('div');
container.classList.add('my-custom-overlay-container-class');
element.appendChild(container);
this._containerElement = container;
/**
* Prevent creation of the HTML element, use custom method above
*/
protected _createContainer(): void
return;
Then in your cdk-overlay-container.directive.ts
your are calling myCreateContainer()
and passing the ElementRef
as an argument.
this.cdkOverlayContainer['myCreateContainer'](this.elementReference.nativeElement);
Then in your HTML assign the directive where you want it to show up.
<div myCdkOverlayContainer
Stackblitz
https://stackblitz.com/edit/angular-material2-issue-6nzwws?embed=1&file=app/app.component.html
Please reference this stackblitz example.
looks like you can accomplish this by extending the
OverlayContainer
class via the following inapp.module.ts
provide: OverlayContainer, useFactory: () => new AppOverlayContainer()
Stackblitz
https://stackblitz.com/edit/angular-material2-issue-ansnt5?file=app%2Fapp.module.ts
This GitHub comment also provides an example of how to package this in a directive
GitHub comment
https://github.com/angular/material2/issues/7349#issuecomment-337513040
Revision 3/22/19 working directive example
Extend the OverlayContainer
class via cdk-overlay-container.ts
Stub the class in app.module.ts
providers: [
provide: OverlayContainer, useClass: CdkOverlayContainer ,
]
In your cdk-overlay-container.ts
you are preventing the default _createContainer()
from working, and providing your own custom public method myCreateContainer
to replace it.
You are essentially creating an empty
div
here, adding a custom class to itmy-custom-overlay-container-class
and appending it to the
div
the directive is attached to, then passing that container to the
private variable_containerElement
in the trueOverlayContainer
class.
/**
* Create overlay container and append to ElementRef from directive
*/
public myCreateContainer(element: HTMLElement): void
let container = document.createElement('div');
container.classList.add('my-custom-overlay-container-class');
element.appendChild(container);
this._containerElement = container;
/**
* Prevent creation of the HTML element, use custom method above
*/
protected _createContainer(): void
return;
Then in your cdk-overlay-container.directive.ts
your are calling myCreateContainer()
and passing the ElementRef
as an argument.
this.cdkOverlayContainer['myCreateContainer'](this.elementReference.nativeElement);
Then in your HTML assign the directive where you want it to show up.
<div myCdkOverlayContainer
Stackblitz
https://stackblitz.com/edit/angular-material2-issue-6nzwws?embed=1&file=app/app.component.html
edited Mar 22 at 15:57
answered Mar 21 at 21:11
MarshalMarshal
3,8272622
3,8272622
Yes, I saw this suggestion, the problem with this is that I might need to provide the custom OverlayContainer per each instance of the tooltip directive. Seems though there is no other way to achieve this. Would be nice if it would be configurable though.
– vlio20
Mar 21 at 21:20
Although I believe the directive approach may be a solution here, I am having trouble implementing it in stackblitz. Will update answer if I can get it going.
– Marshal
Mar 21 at 22:28
Please see revision with directive example.
– Marshal
Mar 22 at 15:50
add a comment |
Yes, I saw this suggestion, the problem with this is that I might need to provide the custom OverlayContainer per each instance of the tooltip directive. Seems though there is no other way to achieve this. Would be nice if it would be configurable though.
– vlio20
Mar 21 at 21:20
Although I believe the directive approach may be a solution here, I am having trouble implementing it in stackblitz. Will update answer if I can get it going.
– Marshal
Mar 21 at 22:28
Please see revision with directive example.
– Marshal
Mar 22 at 15:50
Yes, I saw this suggestion, the problem with this is that I might need to provide the custom OverlayContainer per each instance of the tooltip directive. Seems though there is no other way to achieve this. Would be nice if it would be configurable though.
– vlio20
Mar 21 at 21:20
Yes, I saw this suggestion, the problem with this is that I might need to provide the custom OverlayContainer per each instance of the tooltip directive. Seems though there is no other way to achieve this. Would be nice if it would be configurable though.
– vlio20
Mar 21 at 21:20
Although I believe the directive approach may be a solution here, I am having trouble implementing it in stackblitz. Will update answer if I can get it going.
– Marshal
Mar 21 at 22:28
Although I believe the directive approach may be a solution here, I am having trouble implementing it in stackblitz. Will update answer if I can get it going.
– Marshal
Mar 21 at 22:28
Please see revision with directive example.
– Marshal
Mar 22 at 15:50
Please see revision with directive example.
– Marshal
Mar 22 at 15:50
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288559%2fangular-cdk-overlay-change-default-overlay-container%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What's your use case for attaching it to a specific element?
– adamdport
Mar 21 at 20:38
I have a dialog, the tooltip appears behind it (the tooltip trigger is placed on the dialog).
– vlio20
Mar 21 at 20:40