I have an issue and can't remember how to get around it. I am subscribing to a callback from a third party directive but not being called back with the correct scope. And by that I mean that when it hits my controller this
is actually some other scope I cant quite figure out so it cannot access any member variables. How do I get back to my controller scope?
<ui-gmap-layer type="HeatmapLayer" onCreated="$ctrl.heatLayerCallback"></ui-gmap-layer>
Component Controller:
heatLayerCallback(heatLayer: google.maps.visualization.HeatmapLayer) {
this.heatMapLayer = heatLayer;
// 'this' here is not my controller
}
If I change the call back to
<ui-gmap-layer onCreated="$ctrl.heatLayerCallback(layer)"></ui-gmap-layer>
Then my callback executes on the right scope (i.e. my controller) but the parameter layer
is lost ;/
Notes
I am using Typescript, Angular 1.6 and Angular Components
You could use bind to bind the callback to the context you want (your controller) or simply store it in another new variable before the callback and access it by that variable within the callback.
Something like:
...or:
The precise syntax may vary depending on where your quoted code lives (e.g. find where "this" is what you want, or use whatever context instead of "this").