I want to use this pretty image cropper in my AngularJS project. When I use it the "normal" way, that is on a plain page, everything works fine. The problem is that I want to put it on to the Bootstrap modal dialog.
In order to initialize the cropper, I am supposed to execute this snippet:
$(".cropper").cropper({
aspectRatio : 1.618,
done : function(data) {
console.log(data);
}
});
But it has to be executed after the DOM of the modal is loaded. So I have tried to run it like this:
$scope.onCropOpen = function() {
var modalInstance = $modal.open({
templateUrl : 'cropModal.html',
controller : CropModalInstanceCtrl
});
modalInstance.opened.then(function() {
$(".cropper").cropper({
aspectRatio : 1.618,
done : function(data) {
console.log(data);
}
});
});
};
Unfortunately, the cropper still is not being initialized. I know that it should work after calling it when the modal is loaded, because I ran it manually from the browser console (with the modal dialog open) and then the cropper "magically" initialized.
$modal.open
, but it's not best solution, you should have some factory which will return cropper constructor, and insideCropModalInstanceCtrl
you will initialize it. – evc Aug 12 '14 at 12:03