ERROR TypeError: Cannot read properties of undefined (reading 'addControls') in Angular 13
See original GitHub issueSimilar to #1220 (and have also had that problem), I am running into map.pm being undefined, and I am not sure why. I created a demo project as a POC and it worked great. I take that same code into my actual project and map.pm always ends up being undefined. Leaflet is imported, then geoman at the head of the ts file, and then my map is init’d the exact same way as my POC, but no dice. Would love any suggestions on where to look.
this.map = map(this.mapId, {
center: [39.8282, -98.5795],
zoom: 3,
});
const tiles = tileLayer(
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{
maxZoom: 18,
minZoom: 3,
attribution:
'© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
}
);
tiles.addTo(this.map);
control.scale().addTo(this.map);
this.featureGroup.addTo(this.map);
function logEvent(e: any) {
console.log(e);
}
this.map.pm.addControls({})
This fails at the addControls() in the real project, but not in POC, with the only difference between real and POC and the mapId. A map is displayed with scale and +/- controls.
Edit:
Trying to get pm working, I tried PM.reInitLayer which also failed with PM being undefined.
Issue Analytics
- State:
- Created a year ago
- Comments:11
Top Results From Across the Web
Cannot read property 'addControl' of null - Stack Overflow
Nested form, trying to add one form inside other but getting error 'Cannot read property 'addControl' of null ...
Read more >cannot read properties of undefined (reading 'controls') angular
To fix Error: TypeError: Cannot read property '…' of undefined with Angular, we should make sure the variable we're rendering is defined.
Read more >FormGroupDirective - Angular
Emits an event when the form submission has been triggered. formDirective: Form, Read-Only. Returns this directive's instance. control: ...
Read more >Null parent form via FormGroupDirective from child ... - GitHub
[x ] Bug report Current behavior This is based on the sub-form demo by @kara ... ERROR TypeError: Cannot read property 'addControl' of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
So, having fiddled and fiddled and fiddled… I saw somewhere someone did a “console.log(L.PM); console.log(L.map.pm)” to get PM initialized. I tried it. It worked. I removed those logs. It still worked. I put it all back to the L import, rebuilt a few times, reload after clearing cache, still seems to be working. I assume I caught something magic in there somewhere that I missed before, but man, I wish I knew what. Thanks for prodding at it with me!