I have an SVG file loaded as an object:
<object data="assets/img/states.svg" type="image/svg+xml" id="map"></object>
This SVG includes a large PNG map along with several rect
and text elements.
<rect
y="224.72084"
x="644.87109"
height="231.68137"
width="101.08391"
id="RECT_TO_GET" />
I want to store all the rect
elements in an array, similar to how I do it with regular HTML elements using Angular's @ViewChildren
:
@ViewChildren('rect') rects !: QueryList<any>;
this.rects.forEach(r=> {
console.log(r);
});
The issue is that the rects
array always remains empty. I've attempted to access them in both ngViewInit()
and ngAfterViewChecked()
without any luck. How can I retrieve elements from an SVG?
I haven't tried using getElementsById()
yet, as I prefer to handle it the Angular way if possible.
The main goal here is to assign specific colors to each rect
element based on their context once retrieved.