-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathangular-croppie.js
41 lines (37 loc) · 979 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
angular.module('angularCroppie', []).
component('croppie', {
bindings: {
src: '<',
ngModel: '=',
options: '<'
},
controller: ['$scope', '$element', function ($scope, $element) {
var ctrl = this;
this.$onInit = function(){
var options = angular.extend({
url: ctrl.src,
viewport: {
width: 200,
height: 200
}
}, ctrl.options);
options.update = function () {
c.result('canvas').then(function(img) {
$scope.$apply(function () {
ctrl.ngModel = img;
});
});
};
var c = new Croppie($element[0], options);
ctrl.$onChanges = function (changesObj) {
var src = changesObj.src && changesObj.src.currentValue;
if(src) {
// bind an image to croppie
c.bind({
url: src
});
}
};
};
}]
});