If you include jQuery and Underscore in your HTML, they will be available worldwide. There is no need to "enter" them.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> <script src="//documentcloud.imtqy.com/underscore/underscore-min.js"></script>
If you want to include them in a module, you can do something like this:
angular.module('myApp', []). service('vendorService', ['$q', '$timeout', '$window', function($q, $timeout, $window){ var deferred = $q.defer(), libs = {}; $script([ '//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js', '//documentcloud.imtqy.com/underscore/underscore-min.js' ], 'vendorBundle'); $script.ready('vendorBundle', function() { libs.$ = $window.jQuery.noConflict(); libs._ = $window._.noConflict(); $timeout(function(){ deferred.resolve(libs); }, 0); }); this.getLibs = function(){ return deferred.promise; } }]). controller('myController', ['$scope', 'vendorService', function($scope, vendorService){ vendorService.getLibs().then(function(libs){ $scope.jQueryVersion = libs.$.fn.jquery; $scope._ = libs._; }); }]);
This will allow you to load libraries asynchronously, preventing them from contradicting previously downloaded versions. There may be a better way to store links to loaded libraries, but this should work fine.
In addition, this example is based on a third-party lacquer ( $ script.js ).
And here is jsFiddle ( http://jsfiddle.net/moderndegree/bzXGx/ );
Brian lewis
source share