Last active
December 30, 2016 17:35
-
-
Save ajsb85/8be7535c06d6d324bb96b7fd523c0389 to your computer and use it in GitHub Desktop.
Load PouchDB with AngularJS
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
| angular.module('myModule').service('loadPouchDB', ['$window', '$q', | |
| function ($window, $q) { | |
| $window.Promise = $q.when(); | |
| var deferred = $q.defer(); | |
| function loadScript() { | |
| // Use global document since Angular's $document is weak | |
| var script = document.createElement('script'); | |
| document.body.appendChild(script); | |
| script.onload = function () { | |
| $window.removeEventListener('load', loadScript, false); | |
| deferred.resolve(); | |
| }; | |
| script.src = 'vendor/pouchdb.js'; | |
| } | |
| $window.addEventListener('load', loadScript, false); | |
| return deferred.promise; | |
| }]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment