Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- angular.module('myApp')
- .factory('ModuleLoader', function ($ocLazyLoad, $compile, $rootScope, $http, MyConfig) {
- // Public API here
- return {
- loadAll: function () {
- if (MyConfig.hasOwnProperty('plugin')) {
- var p;
- var arrPlugins = [];
- var scope = $rootScope.$new();
- for(p in MyConfig.plugin){
- if (MyConfig.plugin.hasOwnProperty(p) && MyConfig.plugin[p]) {
- MYFP.util.loadJS('src/webcomponent/'+p.toLowerCase()+'/'+p.toLowerCase()+'.js');
- //arrPlugins.push('src/webcomponent/'+p.toLowerCase()+'/'+p.toLowerCase()+'.js');
- // $http.get('src/webcomponent/'+p.toLowerCase()+'/'+p.toLowerCase()+'.js').then(function (a,b,c) {
- // console.log(a)
- // });
- $ocLazyLoad.load({
- name: p.toLowerCase(),
- files: ['src/webcomponent/'+p.toLowerCase()+'/'+p.toLowerCase()+'.js'],
- serie: true
- }).then(function () {
- var el, elToAppend;
- elToAppend = $compile('<my-test-plugin></my-test-plugin>')(scope);
- el = angular.element('body').find('my-test-plugin').parent();
- angular.element('body').find('my-test-plugin').remove();
- el.append(elToAppend);
- }, function (e) {
- console.log(e);
- });
- };
- };
- // return $ocLazyLoad.load({
- // name: '',
- // files: arrPlugins
- // });
- }else{
- return undefined;
- };
- },
- loadFile: function (files) {
- return $ocLazyLoad.load(files);
- }
- };
- });
- 'use strict';
- angular.module('testplugin', [])
- .controller('TestPlugin', function ($scope, MyContent) {
- $scope.title = MyContent.title;
- })
- .directive('myTestPlugin', function () {
- return {
- restrict: 'E',
- template: '<div ng-controller="TestPlugin">My title is {{title}}</div>'
- };
- })
- .directive('myTestPlugin222', function () {
- return {
- restrict: 'E',
- template: '<div ng-controller="TestPlugin">My title is {{title}}</div>'
- };
- })
- .directive('myTestPlugin333', function () {
- return {
- restrict: 'E',
- template: '<div ng-controller="TestPlugin">My title is {{title}}</div>'
- };
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement