I have the following example:
<div #containerRef class="container">
<app-component-1>
<div id="el1"></div>
</app-component-1>
<app-component-2>
<div id="el2"><div>
</app-component-2>
<app-line-component>
<svg style="position: absolute">
<line
[attr.x1]="linePositionX1"
[attr.y1]="linePositionY1"
[attr.x2]="linePositionX2"
[attr.y2]="linePositionY2"
style="stroke: rgb(255, 0, 0); stroke-width: 2;"/>
</svg>
</app-line-component>
</div>
I want to drew a SVG (line) inside the app-line-component between elements el1
and el2
, witch both of them created dynamically and located inside two separate components in the main container.
My current TS code inside app-line-component:
public createLine(): void {
const elOneHtml: HTMLElement | null = document.getElementById(el1);
const elTwoHtml: HTMLElement | null = document.getElementById(el1);
const parentDomRect: DOMRect = containerRef.nativeElement.getBoundingClientRect();
const elOnerect: DOMRect = elOneHtml.getBoundingClientRect();
const elTwoRect: DOMRect = elTwoHtml.getBoundingClientRect();
}
The issue is that I'm not sure what I should do next, how exactly can I find the coordinates that I need for the SVG (e.g x2, y2, width)?