Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs, how to configure a module?

Tags:

angularjs

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

like image 252
Milen Kovachev Avatar asked Jan 26 '26 09:01

Milen Kovachev


1 Answers

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

like image 59
Narek Mamikonyan Avatar answered Jan 28 '26 01:01

Narek Mamikonyan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!