0

I know the question has been asked before. But the solutions doesnt work for my problem. I use Angular to build a mobile App. So my code run in a mobile Application.
I trie solutions from Angular 2: Get position of HTML element and Retrieve the position (X,Y) of an HTML element relative to the browser window I hope Anguar have a new function to get the pixel position from a html element.

RavenClow
  • 49
  • 4
  • I don't think I eve saw some wrapper for that feature in neither Angular nor CDK, but I might be wrong. But even if it did - there's not much more that can be done, as Angular compiles to pure old javascript and renders stuff in DOM. It would be helpful if you described what you're trying to achieve and why the standard methods don't work for you. – TotallyNewb Apr 06 '21 at 07:25

1 Answers1

0

Your problem is most likely related to your smartphone's browser. Are you using Samsung Internet? If certain angular-features turn out not to be supported by your browser you can write polyfills to implement functions that fit your needs.

https://angular.io/guide/browser-support

For mobile browser debugging follow these guides:

https://raygun.com/blog/debug-android-chrome/

https://developer.mozilla.org/de/docs/Tools/Remote_Debugging

Anyways it would be helpful to know, why the linked solutions don't work for you. Wanting to have the pixel position of an Element is inaccurate. Do you want it relative to it's parent-container, relative to the body, relative to the window or document?

If the native solutions don't work (document.getElementById and el.offsetTop) you're probably using them in the wrong lifecycle hook. You want to use certain functions only after your HTML is actually rendered. For that you implement the "afterViewInit"-function:

https://angular.io/api/core/AfterViewInit

Quirynn
  • 26
  • 2