Romanovich095

SettingsProvider

Jul 13th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. angular.module('SettingsProvider', [])
  2.     .provider('settings', [function () {
  3.         /**
  4.          * Templates paths
  5.          */
  6.         this.templates = new function () {
  7.             this.root = '/js/application/templates';
  8.             this.component = `${this.root}/components`;
  9.             this.header = `${this.component}/headers`;
  10.             this.footer = `${this.component}/footers`;
  11.         };
  12.  
  13.         /**
  14.          * Generate Router object
  15.          *
  16.          * @param type
  17.          * @param name
  18.          * @param controllerName
  19.          * @returns {{templateUrl: string, controller: *}}
  20.          */
  21.         this.generateRouter = function (type, name, controllerName) {
  22.  
  23.             let controllerExists = typeof window[controllerName] === 'function',
  24.                 template = {};
  25.  
  26.             template.templateUrl = `${this.templates[type]}/${name}.html`;
  27.  
  28.             if (controllerExists) {
  29.                 template.controller = `${controllerName}Controller`;
  30.             }
  31.  
  32.             console.log(`Rendering ${type} ${name}`);
  33.  
  34.             return template;
  35.         };
  36.  
  37.         this.$get = function () {
  38.             return this;
  39.         };
  40.     }]);
Advertisement
Add Comment
Please, Sign In to add comment