I'm new to angular. I couldn't figure how to access a variable inside a function(). this is my code
mergeImages() {
var imgurl;
var canvas: HTMLCanvasElement = this.canvas.nativeElement;
var context = canvas.getContext('2d');
let img1 = new Image();
let img2 = new Image();
img1.onload = function() {
canvas.width = img1.width;
canvas.height = img1.height;
context.globalAlpha = 1.0;
img2.src = '../assets/sun.jpg';
};
img2.onload = function() {
context.globalAlpha = 1;
context.drawImage(img1, 0, 0);
context.globalAlpha = 0.5; //Remove if pngs have alpha
context.drawImage(img2, 0, 0);
imgurl = canvas.toDataURL("image/jpg");
//console.log(imgurl)
};
img1.src = '../assets/moon.jpg';
}
now I need to access "imgurl" from another method
printvalue(){
need to access imgurl
}
edit 1 - problem is angular cannot find var a on printvalue() it's only working inside function something()