Closed darkmavis1980 closed 8 years ago
You can load files from anywhere you want, just use the full url to your file.
I did try it, but it simply doesn't work, it doesn't even start the call looking at the network traffic
Do you have a code example ?
What I did it was simply to try to load a module, using the $ocLazyLoad service in this way
$ocLazyLoad.load('https://s3.amazonaws.com/mybucket/module.js');
This simply contains a module (already existing in my application) that append a new service to the app, something like this
angular.module('myapp')
.service('TestService', function(){
console.log('test');
this.test = 'hello';
})
.directive('helloWorld', function(TestService){
return {
restrict: 'E',
templateUrl: 'test/template.html',
controller: function($scope, $element, $attrs){
$scope.hello = TestService.test;
}
}
})
And then I inject the TestService into one of my controllers to see if it's loaded.
If I load the file locally, just using $ocLazyLoad.load('test/module.js');
it works fine, I can see the console log, I can see the directive working, no problem. But if I use the same file but on S3, it will just not load anything and my app will throw an error saying that TestService doesn't exists (obviosly).
Also I'm using it with Angular 1.5.7
@darkmavis1980 - I can load my module from a remote site. Please make sure server supports CORS.
@trunghaiy I'm fairly sure that the CORS permission are fine as we use that S3 for other things, but I'll double check
I know it's pretty old post but just in case if somebody faced the same problem. To make it work you need to remove any links to the library - no matter, local, or remote. The only place where you put it is in $ocLazyLoad.load() function.
So this library can load only local files, but it would be nice if you could load also remote javascript libraries, perhaps stored on S3 (but the concept should be applied from any source).