forked from bettysteger/angular-croppie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular-croppie.js
50 lines (40 loc) · 970 Bytes
/
angular-croppie.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require('croppie/croppie.css');
const Croppie = require('croppie');
angular.module('ovi.croppie', []).
component('croppie', {
bindings: {
src: '<',
ngModel: '=',
options: '<'
},
controller: Controller
});
function Controller($scope, $element) {
var ctrl = this;
var options = angular.extend({
viewport: {
width: 200,
height: 200
}
}, ctrl.options);
var resultOptions = angular.extend(
{type:'canvas', format:'jpeg'},
options.result
);
options.update = function () {
c.result(resultOptions).then(function(img) {
$scope.$apply(function () {
ctrl.ngModel = img;
});
});
};
var c = new Croppie($element[0], options);
$scope.$watch(function(){
return ctrl.src;
}, function (newSrc) {
if(!ctrl.src) { return; }
// bind an image to croppie
c.bind({ url: newSrc, zoom: 0 });
});
}
Controller.$inject = ['$scope', '$element'];