angularjs - Angular Controller can inject service just fine but $injector.get can't? -
i have extremely edge case scenario have callback method have define during config. means no scope, no factories, etc... work around use root injector ($injector) , other modules @ runtime.
however, when call $injector.get('myservicename') in call (after application running) "unknown provider". same service has no problem (and is) being injected before line of code running. if call $injector.get("myservicenameprovider") can provider in callback.. service has factory can't @ all.
so in extremely bad practice, how can snag service configured. heck can't seem $rootscope..
angular inits providers first, factories/services - services not available in app.config
.
you can deo this:
app.config(... window.on('scroll', function() { // executed later $injector.get()... })
or use app.run
services available.
Comments
Post a Comment