Skip to content

Instantly share code, notes, and snippets.

@christophermina
Created October 12, 2014 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christophermina/740c5a5d4e549216acc9 to your computer and use it in GitHub Desktop.
Save christophermina/740c5a5d4e549216acc9 to your computer and use it in GitHub Desktop.
define([
'/path/to/a/dependency'
], function(myDependcy) {
var module = angular.module('asyncModule', [myDependency.name]);
module.directive('asyncDirective', ['$http'', function($http) {
return {
link: function(scope, element, attrs) {
... Do stuff in our directive ...
}
}
}]);
return module;
})
define([
], function() {
var module = angular.module('mainApp');
module.directive('parentDirective', ['$ocLazyLoad', function($ocLazyLoad) {
return {
link: function(scope, element, attrs) {
// This method called from user interaction
scope.loadAsyncModule = function () {
var self = this;
$ocLazyLoad.load({
name: 'asyncModule', //Same name as defined in asyncmodule.js
files: ['/path/to/asyncdirective.js']
})
.then(function() {
//Our module is now fully loaded, we can use it as we would any other module
});
}
};
}
}]);
return module;
}) ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment