3

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

1
  • Short version, time of execution. Will give detailed answer tomorrow when i am back at a computer. Config fires first Commented Jul 5, 2014 at 3:10

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.