I want to create a md-dialog box using Angular material which show the choose file option for image selection. Once image selected, it should show the image and provide crop facility and also provide the preview of the crop image. For cropping, I am using ng-img-crop
Below is my link which trigger the md-dialog:
<span class="edit_image" ng-click="uploadPic()">
Below is my controller function called by above function:
$scope.uploadPic = function(ev){
var useFullScreen = ($mdMedia('sm') || $mdMedia('xs')) && $scope.customFullscreen;
$mdDialog.show({
controller: imageUploadCtrl,
templateUrl: 'uploadImage.tmpl.html',
parent: angular.element(document.body),
targetEvent: ev,
clickOutsideToClose:true,
fullscreen: useFullScreen
});
Below is my html template which i am using:
<div>Select an image file: <input type="file" id="fileInput" /></div>
<div class="cropArea">
<img-crop image="myImage" result-image="myCroppedImage"></img-crop>
</div>
<div>Cropped Image:</div>
<div><img ng-src="{{myCroppedImage}}" /></div>
<md-dialog-actions layout="row">
<md-button ng-click="cancel()">
Cancel
</md-button>
<span flex></span>
<md-button type="submit" class="md-raised md-primary" ng-click="saveImage()">
Upload
</md-button>
</md-dialog-actions>
Image upload controller :
function imageUploadCtrl($scope, $mdDialog){
$scope.myImage='';
$scope.myCroppedImage='';
var handleFileSelect=function(ev) {
console.log('trigger');
var file=ev.currentTarget.files[0];
var reader = new FileReader();
reader.onload = function (ev) {
$scope.$apply(function($scope){
$scope.myImage=ev.target.result;
});
};
reader.readAsDataURL(file);
};
angular.element(document.querySelector('#fileInput')).on('change',handleFileSelect);
$scope.hide = function () {
$mdDialog.hide();
};
$scope.cancel = function () {
$mdDialog.cancel();
};
$scope.saveImage = function () {
Notifier.success("Image Uploaded Sucessfully");
$mdDialog.hide();
};
}
Above code is perfectly working, if I am doing this process in a new page. But not working in md-dialog box. Can anyone please help me to complete it.