Issue
In jQuery we had the position()
method:
$("button").click(function(){
var x = $("p").position();
alert("Top: " + x.top + " Left: " + x.left);
});
It will return the position of an element. How can I do the same in Angular?
Solution
Please try:
In component.html, define reference to html tag:
<p #position>I want to go back here</p>
In component.ts:
@ViewChild('position') HoldPosition: ElementRef;
clickFunction() {
console.log(this.HoldPosition.nativeElement.offsetTop);
console.log(this.HoldPosition.nativeElement.offsetLeft);
}
```
Answered By - Ryan Huang
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.