Quick and easy Angular cropper that supports Load-On-Demand in large SPA applications
npm install angular-cropGood practice to build large scale SPA applications:
http://weblogs.asp.net/dwahlin/dynamically-loading-controllers-and-views-with-angularjs-and-requirejs
http://www.codeproject.com/Articles/808213/Developing-a-Large-Scale-Application-with-a-Single
console
npm install angular-crop
`Dependencies
JcropUsage
angular-crop is an object containing a directive method and a service method that you can feed it to angular.directive() and
angular.service() directly.
directive: js function, you can feed it to angular.directive() as second parameter;
service: js function, you can feed it to angular.service() as second parameter;
traditional global namespace
include files:
`html
`
controller:
`js
var app = angular.module('app', []);
app.directive('angularCrop', angularCrop.directive);
app.controller('controllerName', function () {
$scope.data = {
x1: 0,
y1: 0,
x2: 200,
y2: 200
};
$scope.events = {
onChange: function () {
console.log('changed', $scope.data);
},
onSelect: function () {
console.log('selected', $scope.data);
}
};
});
`
view:
`html
![]()
`load angular-crop using requireJS
controller:
`js
define(['app', 'angular-crop'], function (app, angularCrop) {
app.register.directive('angularCrop', angularCrop.directive);
app.register.controller('controllerName', function ($scope, $css) {
$css.bind({href: 'app/views/css/jquery.Jcrop.css'}, $scope);
$scope.data = {
x1: 0,
y1: 0,
x2: 200,
y2: 200
};
$scope.events = {
onChange: function () {
console.log('changed', $scope.data);
},
onSelect: function () {
console.log('selected', $scope.data);
}
};
});
});
`
view:
`html
![]()
`or you can use service instead of directive.
controller:
`js
define(['app', 'angular-crop'], function (app, angularCrop) {
app.register.service('angularCrop', angularCrop.service);
app.register.controller('controllerName', function ($scope, $css, angularCrop) {
$css.bind({href: 'app/views/css/jquery.Jcrop.css'}, $scope);
$scope.data = {
x1: 0,
y1: 0,
x2: 200,
y2: 200
};
$scope.events = {
onChange: function () {
console.log('changed', $scope.data);
},
onSelect: function () {
console.log('selected', $scope.data);
}
};
angularCrop.angularCrop($('#imgID'), $scope.data, $scope.events);
});
});
`
view:
`html
![]()
`API
`html
![]()
``events is an object containing:
* onChange: Called when the selection is moving
* onSelect: Called when the selection is completed