4

Can anyone explain me difference between $routeand $routeProvider?

0xc0de
  • 7,578
  • 5
  • 46
  • 73
Stepan Suvorov
  • 23,436
  • 25
  • 100
  • 172

2 Answers2

8

Services are singletons. They are instantiated the first time they are needed. Sometimes you have to configure a service before running it, for example in the .config part of the application module. This is where you use $routeProvider. After this, you can use the service instance (e.g. $route) normally, for example in the .run block of the app module. Notice that with $routeProvider you define the routes (a configuration) and with $route you use methods that depend on the configuration.

There are three ways of defining services: the simplest is using service, then you can also use a factory and, if you need complex configuration, you use a provider AngularJS: Service vs provider vs factory

Community
  • 1
  • 1
Eduard Gamonal
  • 7,953
  • 5
  • 39
  • 44
2

As @elclanrs pointed out, there's not $router that I know of. So I presume you mean the difference between $route and $routeProvider

The $route is used to deep-link URLs to Controllers and Views. It watches the location urls and tries to map it to existing paths. The $route is configured(defined) with the $routeProvider.

Here is the official documentation $route , $routeProvider

IUnknown
  • 868
  • 6
  • 18
  • yes, of course I've read docs. For me unclear such naming. Because if we look at other providers we can see that each has "name" and "nameProvide" - that is private function and just link to the "name" – Stepan Suvorov Jul 27 '13 at 08:50