how to structure large applications with angularjs

34
HOW TO STRUCTURE LARGE APPLICATIONS WITH ANGULARJS

Upload: stefan-unterhofer

Post on 07-May-2015

1.371 views

Category:

Software


0 download

DESCRIPTION

Slides from my talk at the 3rd Vienna AngularJS Meetup about using AngularJS in large applications.

TRANSCRIPT

Page 1: How To Structure Large Applications With AngularJS

HOW TOSTRUCTURE LARGE APPLICATIONS WITH ANGULARJS

Page 2: How To Structure Large Applications With AngularJS

by STEFAN UNTERHOFERSOFTWARE DEVELOPER AT CATALYSTS

Page 3: How To Structure Large Applications With AngularJS

PART 1THE PREMISE

Page 4: How To Structure Large Applications With AngularJS

COMPLETE REWRITE OF A LARGE APPLICATION

Page 5: How To Structure Large Applications With AngularJS

JAVA BACKENDANGULARJS FRONTEND

Page 6: How To Structure Large Applications With AngularJS

MORE THAN 10 SUBMODULES

Page 7: How To Structure Large Applications With AngularJS

MULTIPLE TEAMS WORKING ON THE SAME CODEBASE

Page 8: How To Structure Large Applications With AngularJS

MOST DEVS HAVE NO JS EXPERIENCE

Page 9: How To Structure Large Applications With AngularJS

PART 2PROJECT STRUCTURE

Page 10: How To Structure Large Applications With AngularJS

SEPARATE DEVELOPMENT STYLES FOR BACKEND AND FRONTEND

Page 11: How To Structure Large Applications With AngularJS

GRUNT & BOWER FOR FRONTEND MODULES

Page 12: How To Structure Large Applications With AngularJS

COMPLETELY ENCAPSULATED ANGULAR MODULES

Page 13: How To Structure Large Applications With AngularJS

BUILD THE WHOLE APPLICATION WITH GRADLE

Page 14: How To Structure Large Applications With AngularJS

PART 3SOME GOOD PRACTICES

Page 15: How To Structure Large Applications With AngularJS

DON'T USE SERVER-SIDE FRAMEWORKS TO RENDER

PAGES

Page 16: How To Structure Large Applications With AngularJS

WRITE DOMAIN CLASSES

Page 17: How To Structure Large Applications With AngularJS

THEY MAKE YOUR CODE MORE UNDERSTANDABLE

Page 18: How To Structure Large Applications With AngularJS

THEY CAN BE EXTENDED WITH CUSTOM FUNCTIONALITY

Page 19: How To Structure Large Applications With AngularJS

USE AN API SERVICE

Page 20: How To Structure Large Applications With AngularJS

// configure the API endpointangular.module('example').config(function($apiProvider) { $apiProvider.endpoint('movie', { url: 'movies', model: window.Movie });});

// use it in the controllerangular.module('example').controller('ExampleCtrl',function($scope,$api){ $api.movie.list().then(function(data) { $scope.movies = data; });});

Page 21: How To Structure Large Applications With AngularJS

IT'S A SINGLE SOURCE OF TRUTH

Page 22: How To Structure Large Applications With AngularJS

IT'S A COMMON INTERFACE FOR YOUR API

Page 23: How To Structure Large Applications With AngularJS

IT'S EASIER TO TEST

Page 24: How To Structure Large Applications With AngularJS

DON'T REPEAT YOURSELF!

Page 25: How To Structure Large Applications With AngularJS

EXTENDING CONTROLLERSvar 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});});

Page 26: How To Structure Large Applications With AngularJS

MIXINSvar 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());});

Page 27: How To Structure Large Applications With AngularJS

COMPOSITION WITH JS OBJECTSvar Pagination = function() { this.page = 1; this.size = 10;}

angular.module('example').controller('ExampleCtrl', function($scope) { $scope.pagination = new Pagination();});

Page 28: How To Structure Large Applications With AngularJS

AVOID SCOPE INHERITANCE

Page 29: How To Structure Large Applications With AngularJS

USE DIRECTIVES WHENEVER ITS

POSSIBLE

Page 30: How To Structure Large Applications With AngularJS

UNIFIED LOOK AND FEEL

Page 31: How To Structure Large Applications With AngularJS

ABSTRACT COMMONLY USED LOGIC

Page 32: How To Structure Large Applications With AngularJS

ONE DIRECTIVE TO PAGE THEM ALL<mme-paginated api="movieApi" collection="movies"> <!-- insert your table/list here! --></mme-paginated>

Page 33: How To Structure Large Applications With AngularJS

github.com/fewagewasd/angular-multimodule-example

Page 34: How To Structure Large Applications With AngularJS

the end