I've been struggling a long time with this, lots of older posts address the issue but in incomplete, indirect or obsolete ways. Its such a common issue, a common solution would be ideal. I cannot/should-not modify the SVG. The svg has an id and all the various groups have ids that I need to interact with.
The issue is that I can't assign a load event to the svg element itself because it isn't loaded yet when my controller runs; And if I assign the on load event to the parent embed tag, well, then I can't access the elements via getElementByID because they aren't loaded yet either.
View:
<div style="width:1000px" ng-controller="Controller">
<embed id="svgObject" width="100%" height="100%" ng-src="{{modelSVG}}" type="image/svg+xml"></embed>
</div>
Controller:
.controller('HomeController',['BaseController','$scope','$location',function (BaseController,scope,location) {
scope.modelSVG = location.protocol() + '://' + location.host() + '/svg/pic.svg';
var svgObject = document.getElementById("svgObject");
svgObject.addEventListener('load', function(){
var svgDocument = svgObject.contentDocument;
**Do lots of stuff to EACH and every shape loadeded (e.g. show/hide, set hover/click events, etc
})
}])
Another attempt to get at the actual svg document
var svgDocument = svgObject.contentDocument ? svgObject.contentDocument : svgObject.contentWindow.document;
I can't believe this is so difficult.