I have found a problem with Angular 4.4.6 when accessing an DOM element by ID from a different component.
In my component, I want to draw a Google Maps for certain uses. As indicated in the examples provided in the API, I do this by including the following in the .html file:
<div id='map'></div>
In the .ts file, I have the following in my ngOnInit
function:
...
var map = new google.maps.Map(document.getElementById('map'), {
...
}
...
This works as expected, and shows a map I can use if I load the component directly as specified in the routing component.
However, if I want to use this component from a different one, as seen next:
<my-selector></my-selector>
I get the following error in the line where I initialize the map.
ERROR TypeError: Cannot read property 'firstChild' of null
Am I missing something? I suspect it has to do with the loading order, but I cannot understand why it works in one case, and not the other.