Contenu connexe Similaire à How To Structure Large Applications With AngularJS (20) How To Structure Large Applications With AngularJS20. // configure the API endpoint
angular.module('example').config(function($apiProvider) {
$apiProvider.endpoint('movie', {
url: 'movies',
model: window.Movie
});
});
// use it in the controller
angular.module('example').controller('ExampleCtrl',function($scope,$api){
$api.movie.list().then(function(data) {
$scope.movies = data;
});
});
25. EXTENDING CONTROLLERS
var BasePaginationCtrl = function($scope) {
$scope.pagination = { page: 1, size: 10 };
};
angular.module('example')
.controller('ExampleCtrl', function($injector, $scope) {
// extend the BasePaginationCtrl
$injector.invoke(BasePaginationCtrl, this, {$scope: $scope});
});
26. MIXINS
var PaginationMixin = function() {
this.page = 1;
this.size = 10;
}
angular.module('example').controller('ExampleCtrl', function($scope) {
// add PaginationMixin functionality to $scope
angular.extend($scope, new PaginationMixin());
});
27. COMPOSITION WITH JS OBJECTS
var Pagination = function() {
this.page = 1;
this.size = 10;
}
angular.module('example').controller('ExampleCtrl', function($scope) {
$scope.pagination = new Pagination();
});
32. ONE DIRECTIVE TO PAGE THEM ALL
<mme-paginated api="movieApi" collection="movies">
<!-- insert your table/list here! -->
</mme-paginated>