SHARE
TWEET

Angular JS module and route loading

WhatEverEU Apr 5th, 2018 210 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Load modules and moudes
  2.  
  3. var mainModules = [
  4.     'ngMaterial',
  5.     'ngMdIcons',
  6.     'ngRoute',
  7.     'plugins',
  8.     'templates',
  9.     'Authentication'
  10. ];
  11.  
  12. function loadModule(modules) {
  13.     if (nmPlugins.length > 0) {
  14.         for (var i = 0; i < nmPlugins.length; i++) {
  15.             modules.push(nmPlugins[i].module);
  16.         }
  17.     }
  18. }
  19.  
  20. loadModule(mainModules);
  21.  
  22. angular.module('core', mainModules).factory('authInterceptor', function() {
  23.     return {
  24.         request: function(config) {
  25.             config.headers = config.headers || {};
  26.             config.headers.authToken = 'Authorized';
  27.  
  28.             return config;
  29.         }
  30.     };
  31. }).config(function(
  32.     $routeProvider,
  33.     $locationProvider,
  34.     $mdThemingProvider,
  35.     $translateProvider,
  36.     $compileProvider,
  37.     $httpProvider
  38. ) {
  39.     function loadRoutes(plugins) {
  40.         if (!plugins) {
  41.             return;
  42.         }
  43.  
  44.         var plugin = null;
  45.  
  46.         var routeMap = {};
  47.  
  48.         for (var i = 0; i < plugins.length; i++) {
  49.             plugin = plugins[i].routes;
  50.             for (var p = 0; p < plugin.length; p++) {
  51.                 if (routeMap[plugin[p].route] && plugin[p].config.primary) {
  52.                     routeMap[plugin[p].route] = plugin[p].config;
  53.                 }
  54.                 if (!routeMap[plugin[p].route]) {
  55.                     routeMap[plugin[p].route] = plugin[p].config;
  56.                 }
  57.             }
  58.         }
  59.  
  60.         for (var route in routeMap) {
  61.             if (route) {
  62.                 $routeProvider.when(route, routeMap[route]);
  63.             }
  64.         }
  65.     }
  66.  
  67.     $routeProvider.otherwise({
  68.         redirectTo: '/'
  69.     });
  70.  
  71.     loadRoutes(nmPlugins);
  72.  
  73. ...............................
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top