AngularJS Providers Factory


Factory is available in run phase.

The Factory recipe constructs a new service using a function with zero or more arguments (these are dependencies on other services). The return value of this function is the service instance created by this recipe.

Factory can create a service of any type, whether it be a primitive, object literal, function, or even an instance of a custom type.

  .factory('endpointFactory', function() {
    return {
      get: function() {
        return '';
  .controller('MainCtrl', function(endpointFactory) {
    var vm = this;
    vm.endpoint = endpointFactory.get();

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

endpoint =