Hi I'm trying to use $window object in the module below.
var testInterceptor = function($provide,$httpProvider,$window){
// actual Code
}
angular.module('MyApp')
.config(testInterceptor);
But the page is throwing the error like below
Uncaught Error: [$injector:modulerr] Failed to instantiate module MyApp due to: Error: [$injector:unpr] Unknown provider: $window
Please help me to resolve this issue.
$window
is a service and can't be used in config phase.
Only providers and constants can be used here.
Read the documentation. https://docs.angularjs.org/guide/module
Configuration blocks - get executed during the provider registrations and configuration phase. Only providers and constants can be injected into configuration blocks. This is to prevent accidental instantiation of services before they have been fully configured.
What you could do is place your necessary code in the run phase. Because you can use services here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With