Comment

Comment by minznerjosh

Really, Services and Factories are just a shorthand way of creating providers.

.factory('foo', function() {

  var foo = {};


  return foo;
});

is the same as:

.provider('foo', function() {

  this.$get = function() {

    var foo = {};


    return foo;

  };
});

And,

.service('foo', function() {

  this.bar = 'bar';
});

is the same as:

.factory('foo', function() {

  function Foo() {

    this.bar = 'bar';

  }


  return new Foo();
});

is the same as:

.provider('foo', function() {

  this.$get = function() {

    function Foo() {

      this.bar = 'bar';

    }


    return new Foo();

  }
});
parent minznerjosh 12 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton