Got an odd problem with angular. I can get this to work with ng-click but I need to use onchange for other reasons.
My code seems to be working fine for other buttons that can be pressed to trigger the same code but when it comes to my upload button it decides not to update the ng-class even though scope.slideMenu is actually logged out as true.
I would also like to close the menu when the user has finished choosing an image/file if someone could help with that as well.
Heres the code:
HTML
<div class="app-slide-menu"
ng-class="{'app-menu-active': slideMenu}">
<form class="app-set-image-file-form">
<label class="app-file-input"
title="Upload Image">
<i class="icon-enter"></i>
<input type="file"
onchange="angular.element(this).scope().setImageFile(this)"
accept="image/*">
</label>
</form>
</div>
Now for the JS:
scope.setImageFile = function (element) {
var reader = new FileReader();
// Converts the image to a data URL.
reader.readAsDataURL(element.files[0]);
scope.slideMenuToggle();
/**
* When chosen image is selected it triggers the onload function to pass the image to the whiteboardService.
* @param event - Saves the event of the input field to get the images data URL.
*/
reader.onload = function (event) {
fabric.Image.fromURL(event.target.result, function (img) {
whiteboardService.uploadImageToCanvas(img);
});
// Resets the form that wraps round the file input to allow the
// user to add more than one of the same file.
// NOTE: This will break other inputs if you put them inside this form
$('.app-set-image-file-form').trigger('reset');
};
};
And the simple toggle JS:
scope.slideMenuToggle = function () {
scope.slideMenu = !scope.slideMenu;
};