Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure phase of angularJS

AngularJS Inititalization

What is going on in the configure phase of bootstrapping angular app. Unable to imagine it. Right now i am confused with providers. SO may be insight to configure phase help me understand whole process.As provider can be injected in config phase.

Thanks.

like image 781
Shreyansh Bele Avatar asked Jul 12 '15 08:07

Shreyansh Bele


1 Answers

An angular application uses services ($http, $location, etc.).

It's sometimes necessary to configure these services before using them. For example, the $location service has two modes of execution: the "normal" mode, and the "html5" mode. $http might need some headers configured before even sending its very first HTTP request.

To configure these services, Angular uses providers. Providers are objects whose role is to accept configuration options during the configuration phase, and then, once everything is set up, to create the unique instance of a service.

So, to configure the $location service, you use its $locationProvider during the configuration phase. Once that phase is done, Angular, during the run phase, will call the provider's $get() method, which will create and return the $location service (hence the name "provider").

like image 153
JB Nizet Avatar answered Nov 11 '22 08:11

JB Nizet