Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with loading Angular $window

Tags:

angularjs

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.

like image 970
robin Avatar asked Mar 14 '23 06:03

robin


1 Answers

$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.

like image 196
yeouuu Avatar answered Mar 29 '23 08:03

yeouuu