Created
May 28, 2015 05:33
-
-
Save arnabdas/50d9bce89a32233fe4ef to your computer and use it in GitHub Desktop.
This AngularJS modules/dependencies thing is a lie
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
| http://michalostruszka.pl/blog/2015/05/21/angular-dependencies-naming-clash/ | |
| /* You can request a factory of a certain module explicitly (without dependency injection) */ | |
| var injector = angular.injector(['thirdParty1']); | |
| var hello1 = injector.get('hello'); | |
| var injector = angular.injector(['thirdParty2']); | |
| var hello2 = injector.get('hello'); | |
| /* You can also use this, to wrap the third party factories into own factories | |
| This allows you to use hello1 and hello2 in all other parts of your application | |
| */ | |
| angular.module('own1', ['thirdParty1']).factory('hello1', function () { | |
| var injector = angular.injector(['thirdParty1']); | |
| var hello = injector.get('hello'); | |
| return hello; | |
| }); | |
| angular.module('own2', ['thirdParty2']).factory('hello2', function () { | |
| var injector = angular.injector(['thirdParty2']); | |
| var hello = injector.get('hello'); | |
| return hello; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment