javascript - Manually bootstrap angular app to create async app initialization -


i trying manually bootstrap angular app in order load data asynchronously app relies on. see article

the problem no matter try cant access instance of factory using angular.injector. see plunker

the problem anytime run code this:

var injector = angular.injector(["myapp", "ng"]); var initservice = injector.get("myservice"); 

i unknown provider errors.

can please me make plunker work, or point me better way create angular app initialization service. thanks,

edited: updated reflect our discussion in comments thread.

to setup initapp() function initialize, asynchronously using promise, app level services required, including factories (as defined in original plunker) can have return promise resolve when initial injections complete; , once done, call bootstrapapplication() method bootstrap angular on page.

function initapp() {   return new promise(function(resolve, reject) {         var injector = angular.injector(["ng","plunker"]);         injector.invoke(['factorytwo', function(factorytwo) {            console.log(factorytwo.test);           resolve();         }]);   }); }   function bootstrapapplication() {   angular.element(document).ready(function() {       angular.bootstrap(document, ["plunker"]);   }); }    initapp().then(bootstrapapplication); 

here's link forked plunker above code snippet working: http://plnkr.co/edit/764aqlzf6rqhwpz1razc?p=preview


Comments

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Using jquery append to add option values into a select element not working -

javascript - Restarting Supervisor and effect on FlaskSocketIO -