Created
December 9, 2013 19:59
-
-
Save nikaspran/7879743 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
function bootstrap(element, modules) { | |
element = $(element); | |
modules = modules || []; | |
// modules.unshift(['$provide', function ($provide) { | |
// $provide.value('$rootElement', element); | |
// }]); | |
modules.unshift('ng'); | |
var injector = element.injector(); | |
console.log(injector); | |
injector.invoke(['$rootScope', '$rootElement', '$compile', '$injector', '$animate', | |
function ($rootScope, $compile, $injector, $animate) { | |
var scope = $rootScope.$new(); | |
scope.$apply(function () { | |
element.data('$injector', $injector); | |
$compile(element)(scope); | |
}); | |
}] | |
); | |
return injector; | |
} | |
angular.module('lifeboard.directives.module', [ | |
'ui.router' | |
]) | |
.directive('lbModule', function () { | |
function link(scope, elements, attributes) { | |
var statePath = '/' + scope.moduleName, | |
modulePath = 'modules' + statePath + statePath, | |
script = document.createElement('script'), | |
element = elements[0], | |
loaded; | |
script.src = modulePath + '.js'; | |
script.onreadystatechange = script.onload = function () { | |
if (!loaded) { | |
bootstrap(element, ['lifeboard.modules.' + scope.moduleName]); | |
} | |
loaded = true; | |
} | |
document.getElementsByTagName('head')[0].appendChild(script); | |
} | |
function templateUrl(element, attributes) { | |
var module = attributes.lbModuleName; | |
return 'modules/' + module + '/' + module + '.html'; | |
} | |
return { | |
restrict: 'E', | |
link: link, | |
templateUrl: templateUrl, | |
scope: { | |
moduleName: '@lbModuleName' | |
} | |
}; | |
}) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment