Can't attach event on newly created Image for navigation

nativescriptcore
android

#1

let image = new Image();
image.src = banner.image_path;
image.stretch=“aspectFit”;
image.on(GestureTypes.tap, function (args: GestureEventData) {
// i want to create a natigation here on tapping the image. How can i Achieve this
});


#2

Use Button.tapEvent or simply "tap" instead of GestureTypes.tap.


#3

Yes, I tried like this
image.on(“tap”, function () {
this._router.navigate([’/main/product’,banner.ads_link]);
});
And the follwing error throws
Capture


#4

Either use arrow function or pass the third parameter (scope), otherwise this won’t be pointing to your component.


#5

Thank you so much bro. :slightly_smiling_face:
It’s working with arrow function.