1

What is difference between provider and factory? I know the difference between factory and service. But could you tell me in simple language what is difference between in provider and factory? I make a demo in which I use both but work fine but what is difference mean when I use provider and when I use factory ? here is my code http://codepen.io/anon/pen/NqWRNw

var app =angular.module('ionicApp',['ionic']);
app.factory('fac',function(){
  var name;
  return {
    getname :function(){
      return  this.name;
    },
    setName:function(name){
      console.log(name)
      this.name=name;
         console.log( this.name)
    }
  }
});
app.controller('cntr',function($scope,fac,pro){
  fac.setName('test');
  console.log(fac.getname()+"--");
  console.log("pro============")
  pro.setName('protest');
  console.log(pro.getname()+"--");
})

app.provider('pro',function(){
  var name;
  return {
    $get :function(){
      return {
        getname:function(){
           return  this.name; 
        },
        setName:function(name){
             this.name=name; 
        }
      }
    }
    }

});
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
user944513
  • 12,247
  • 49
  • 168
  • 318
  • but there it is not written where we use provide and where we use factory – user944513 Apr 22 '15 at 07:41
  • "... the Provider recipe is the core recipe type and all the other recipe types are just syntactic sugar on top of it. It is the most verbose recipe with the most abilities, but for most services it's overkill." Use it when you need to. – dting Apr 22 '15 at 07:42

0 Answers0