Reputation: 381
I'm converting a old angular 1.x site and I've come upon a section of the code that I'm stuck at.
Old Code :
var loaded = vm.cartMap.on('load', function() {
loaded.remove();
setupExtentLayer();
});
function setupExtentLayer() {
esriLoader.require(['esri/layers/GraphicsLayer'], function (GraphicsLayer) {
vm.extentLayer = new GraphicsLayer();
vm.cartMap.addLayer(vm.extentLayer);
if (vm.cartItems.length > 0) {
_updateCartStatus();
}
});
}
New Code :
const loaded = this.cartMap.on('load', function() {
loaded.remove();
this.setupExtentLayer();
});
setupExtentLayer() {
loadModules(['esri/layers/GraphicsLayer']).then(([GraphicLayer]) => {
this.extentLayer = new GraphicLayer();
this.cartMap.addLayer(this.extentLayer);
if (this.cartItems.length > 0) {
this._updateCartStatus();
}
});
}
My problem is in the angular 2.6 code doesn't recognize the method setupExtentLayer().
What am I missing here?
Upvotes: 0
Views: 43
Reputation: 1413
Problem is in JS
with context this
, not in Angular 2
.
this.cartMap.on('load', function() {
loaded.remove();
this.setupExtentLayer(); // js this
}.bind(this)); // bind this to function
Upvotes: 1
Reputation: 226
You probably need to bind the setupExtentLayer
function within the parent class constructor.
something like -
this.setupExtentLayer = this.setupExtentLayer.bind(this);
Upvotes: 2