简体   繁体   中英

Getting the position of an element inside an Angular Material Dialog Container

I'm trying to retrieve an element inside a material dialog container so that I can use it's position.

I am using Material Angular , and specifically the Dialog .

So far I have tried the getBoundingClientRect() after getting the element with it's associated id.

Using document.getElementById(elementId).getBoundingClientRect() returns {"x":0,"y":0,"width":0,"height":0,"top":0,"right":0,"bottom":0,"left":0}

Where elementId is the id of the button that is inside the mat-dialog.

For anyone that comes across this from my stupidity, the answer is that the element I was looking for was hidden and had no position.

I had two buttons with the same id, and it just got the first one that was in the DOM.

Changing the id of the button fixed that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM