Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. 'use strict';
  2.  
  3. angular.module('myApp')
  4. .factory('ModuleLoader', function ($ocLazyLoad, $compile, $rootScope, $http, MyConfig) {
  5.  
  6. // Public API here
  7. return {
  8.  
  9. loadAll: function () {
  10.  
  11. if (MyConfig.hasOwnProperty('plugin')) {
  12.  
  13. var p;
  14. var arrPlugins = [];
  15. var scope = $rootScope.$new();
  16.  
  17. for(p in MyConfig.plugin){
  18.  
  19. if (MyConfig.plugin.hasOwnProperty(p) && MyConfig.plugin[p]) {
  20. MYFP.util.loadJS('src/webcomponent/'+p.toLowerCase()+'/'+p.toLowerCase()+'.js');
  21. //arrPlugins.push('src/webcomponent/'+p.toLowerCase()+'/'+p.toLowerCase()+'.js');
  22.  
  23. // $http.get('src/webcomponent/'+p.toLowerCase()+'/'+p.toLowerCase()+'.js').then(function (a,b,c) {
  24. // console.log(a)
  25. // });
  26.  
  27. $ocLazyLoad.load({
  28. name: p.toLowerCase(),
  29. files: ['src/webcomponent/'+p.toLowerCase()+'/'+p.toLowerCase()+'.js'],
  30. serie: true
  31. }).then(function () {
  32.  
  33. var el, elToAppend;
  34. elToAppend = $compile('<my-test-plugin></my-test-plugin>')(scope);
  35. el = angular.element('body').find('my-test-plugin').parent();
  36. angular.element('body').find('my-test-plugin').remove();
  37. el.append(elToAppend);
  38.  
  39. }, function (e) {
  40. console.log(e);
  41. });
  42.  
  43. };
  44.  
  45. };
  46.  
  47. // return $ocLazyLoad.load({
  48. // name: '',
  49. // files: arrPlugins
  50. // });
  51.  
  52. }else{
  53. return undefined;
  54. };
  55.  
  56. },
  57. loadFile: function (files) {
  58. return $ocLazyLoad.load(files);
  59. }
  60.  
  61. };
  62.  
  63. });
  64.  
  65. 'use strict';
  66.  
  67. angular.module('testplugin', [])
  68. .controller('TestPlugin', function ($scope, MyContent) {
  69. $scope.title = MyContent.title;
  70. })
  71. .directive('myTestPlugin', function () {
  72. return {
  73. restrict: 'E',
  74. template: '<div ng-controller="TestPlugin">My title is {{title}}</div>'
  75. };
  76. })
  77. .directive('myTestPlugin222', function () {
  78. return {
  79. restrict: 'E',
  80. template: '<div ng-controller="TestPlugin">My title is {{title}}</div>'
  81. };
  82. })
  83. .directive('myTestPlugin333', function () {
  84. return {
  85. restrict: 'E',
  86. template: '<div ng-controller="TestPlugin">My title is {{title}}</div>'
  87. };
  88. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement