EDIT: the following example doesn't do any useful work. It's just to illustrate my problem setting template variables from within img.onload
. The actual image manipulation doesn't matter.
So I'm trying to convert an image to base64 as proposed in this answer and then adapt it for use in an angular project.
I can get the image encoded to base64, but then I can't get that data to appear in a template.
In my controller, I have the following:
vm.showInTemplate = "cluck";
var img = new Image();
img.src = 'http://upload.wikimedia.org/wikipedia/commons/4/4a/Logo_2013_Google.png';
img.onload = function(){
// logic removed for simplicity
vm.showInTemplate= "moooo";
};
Then in the view, I have (for now):
{{ vm.showInTemplate }}
I know from Chrome console that vm.showInTemplate
is available in img.onload()
and I know that it is being set to "moooo"
, but in the template view, the value remains "cluck"
What am I doing wrong?