Design Patterns in angular
Services->constructor DP
Factory->factory DP
Provider->Factory , can be configured
Factory
Services->constructor DP
Factory->factory DP
Provider->Factory , can be configured
Factory
mainApp.factory('ProductService', function(){var obj={}obj.save=function(Product){this.contacts.push(Product);}};return obj;
Provider
whenever we use Provider, it should contain $get() method
it should return an object
//Defining provider
App.provider('configurable',function(){
var roi=2;
this.setRoi=function(rate)
{
roi=rate;
}
this.$get=function()
{
return{
rate:roi,getInterest:function(p,t)
{
var i= p* this.rate*t/200;
return i ;
}
};
};
};
);
No comments:
Post a Comment