geekAbyte: Difference Between Value, Factory, and Service in AngularJs

  • Using Constructor function: Reference
  • var BenzObj = function() { this.model = “Mercedes-Benz CLS Coupé”, this.getModel = function () {return this.model} }; var carObj = new BenzObj(); console.log(carObj.getModel()); // prints Mercedes-Benz CLS Coupé I once wrote about the Constructor function.
  • angular.module(‘carsModule’, []) // registers the constructor function .service(“carObj”, function() { this.model = “Mercedes-Benz CLS Coupé”, this.getModel = function () {return this.model} }) .controller(“Cars_Controller”, [“carObj”, function(car) { // Angular Injects the carObj by // calling new on the constructor function passed in console.log(car); }]) Irrespective of whether we pass the function directly in or not, what is going on remains the same.

Read the full article, click here.


@dadepo: “Difference Between Value, Factory, and Service in AngularJs”



geekAbyte: Difference Between Value, Factory, and Service in AngularJs

You might also like More from author

Comments are closed, but trackbacks and pingbacks are open.