Milen Kovachev
Milen Kovachev

Reputation: 5361

Angularjs, how to configure a module?

I am new to Angularjs but I believe I am past the basics and trying to understand some best practices now. With that said I am looking at a code, which I cannot fully understand:

 ciApp = angular.module("myApp", ["$strap.directives", "ngCookies"]).
    config(["$provide", function (e) {

        e.value("appVersion", "1.0"),
        e.value("appSupportUrl", "https://myknowledgeb as.com/")
    }
     ]).
    value("$anchorScroll", null).
    value("$location", null).
    run(["$rootScope", "version", "$log", function (n, ) {
        log.log("Starting my app")
    }
 ]);

What is the difference between calling module.config(["$provide", function (e) and setting services on the $provider and module().value("", ...)? And is there a difference at all?

Also is value("$anchorScroll", null) the best way to disable the $anchorScroll service?

Thanks

Upvotes: 3

Views: 166

Answers (1)

Narek Mamikonyan
Narek Mamikonyan

Reputation: 4611

Angular.js has five methods different methods for creating services:

  • factory()
  • service()
  • constant()
  • value()
  • provider()

I dont want to go deeper in the differences of each of this, in shortly I can say what

If we want to be able to configure the service in the config() function, we must use provider() to define our service.

and also

The major difference between the value() method and the constant() method is that you can inject a constant into a config function, whereas you cannot inject a value.

form ng-book

Upvotes: 2

Related Questions