aboalkhair

oclazyload - Load modules on demand (lazy load) with angular

Nov 16th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. //the module
  2. https://github.com/ocombe/ocLazyLoad/blob/master/dist/ocLazyLoad.js
  3.  
  4. //the article
  5. https://ciphertrick.com/2016/07/06/lazy-load-modules-and-controllers-in-angularjs/
  6.  
  7. var app = angular.module('lazyLoadApp', ['ui.router', 'oc.lazyLoad']);
  8. app.config(['$ocLazyLoadProvider', '$stateProvider', '$urlRouterProvider' , function($ocLazyLoadProvider, $stateProvider, $urlRouterProvider) {
  9. $urlRouterProvider.otherwise("/state1");
  10. //Config For ocLazyLoading
  11. $ocLazyLoadProvider.config({
  12. 'debug': true, // For debugging 'true/false'
  13. 'events': true, // For Event 'true/false'
  14. 'modules': [{ // Set modules initially
  15. name : 'state1', // State1 module
  16. files: ['app/components/state1/state1Module.js']
  17. },{
  18. name : 'state2', // State2 module
  19. files: ['app/components/state2/state2Module.js']
  20. }]
  21. });
  22. //Config/states of UI Router
  23. $stateProvider
  24. .state('state1', {
  25. url: "/state1",
  26. views : {
  27. "" : {
  28. templateUrl:"app/components/state1/state1View.html"
  29. }
  30. },
  31. resolve: {
  32. loadMyCtrl: ['$ocLazyLoad', function($ocLazyLoad) {
  33. return $ocLazyLoad.load('state1'); // Resolve promise and load before view
  34. }]
  35. }
  36. })
  37. .state('state2', {
  38. url: "/state2",
  39. views : {
  40. "" : {
  41. templateUrl:"app/components/state2/state2View.html"
  42. }
  43. },
  44. resolve: {
  45. loadMyCtrl: ['$ocLazyLoad', function($ocLazyLoad) {
  46. return $ocLazyLoad.load('state2'); // Resolve promise and load before view
  47. }]
  48. }
  49. });
  50. }]);
Advertisement
Add Comment
Please, Sign In to add comment