I am a little confused about the following Angular.js concepts:
- factory
- service
- dependency injection
Can anyone brief me on each one with a simple example or explanation? Any help would be appreciated.
I am a little confused about the following Angular.js concepts:
Can anyone brief me on each one with a simple example or explanation? Any help would be appreciated.
 
    
     
    
    These concepts are part of JavaScript core.
RegExp is a Factory:
console.log(RegExp("[0-9]") );
console.log(RegExp("[a-z]") );
console.log(RegExp("[A-Z]") );
console.log(RegExp("[0-9a-zA-Z]") );Math is a Service:
console.log(Math.PI);
console.log(Math.round(Math.PI));
console.log(Number(Math.random() * 1000).toFixed());
console.log(Number(Math.random() * 10).toPrecision(2));
console.log(Math.floor(Math.random() * 20) + 1);call and apply are Dependency Injection:
"use strict";
var foo = {
    min: function min(array) {
        return Math.min.apply(Math, array);
    },
    max: function max(array) {
        return Math.max.apply(Math, array);
    }
};
var bar = foo.min([1,2,3]);
var baz = foo.max([1,2,3]);
console.log("bar: " + bar);
console.log("baz: " + baz);References
