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?













1















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));










share|improve this question
























  • 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















1















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));










share|improve this question
























  • 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













1












1








1


1






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));










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












1 Answer
1






active

oldest

votes


















1














Please reference this stackblitz example.




looks like you can accomplish this by extending the
OverlayContainer class via the following in app.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 it my-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 true OverlayContainer
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






share|improve this answer

























  • 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











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
);



);













draft saved

draft discarded


















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









1














Please reference this stackblitz example.




looks like you can accomplish this by extending the
OverlayContainer class via the following in app.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 it my-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 true OverlayContainer
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






share|improve this answer

























  • 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















1














Please reference this stackblitz example.




looks like you can accomplish this by extending the
OverlayContainer class via the following in app.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 it my-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 true OverlayContainer
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






share|improve this answer

























  • 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













1












1








1







Please reference this stackblitz example.




looks like you can accomplish this by extending the
OverlayContainer class via the following in app.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 it my-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 true OverlayContainer
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






share|improve this answer















Please reference this stackblitz example.




looks like you can accomplish this by extending the
OverlayContainer class via the following in app.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 it my-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 true OverlayContainer
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







share|improve this answer














share|improve this answer



share|improve this answer








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

















  • 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



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현