AngularJS Providers Service


Service is available in run phase.

The Service recipe produces a service just like the Value or Factory recipes, but it does so by invoking a constructor with the new operator. The constructor can take zero or more arguments, which represent dependencies needed by the instance of this type.

  .service('endpointService', function() {
    this.get = function() {
      return '';
  .controller('MainCtrl', function(endpointService) {
    var vm = this;
    vm.endpoint = endpointService.get();

<body ng-controller="MainCtrl as vm">
  <div>endpoint = {{::vm.endpoint }}</div>

endpoint =