0

Lets say I have my code as below

var app = angular.module("myApp", []);
app.controller("Customerfactory", Customerfactory); 

app.service("Address",Address);
app.service("Phone",Phone);

app.service("customer",customer);
app.service('CreateFactory',CreateFactory);

I want to inject Address and Phone service into customer service and then customer service into createFactory service using Array Injection technique.

Any thoughts.

Anik Islam Abhi
  • 25,137
  • 8
  • 58
  • 80
  • possible duplicate of [Injecting a service into another service in angularJS](http://stackoverflow.com/questions/21004760/injecting-a-service-into-another-service-in-angularjs) – bahadir Sep 18 '15 at 11:02

3 Answers3

2

Try like this

app.service("customer",['Address','Phone',function(Address,Phone){


}]);

app.service('CreateFactory',['customer',function(customer){

}]);
Anik Islam Abhi
  • 25,137
  • 8
  • 58
  • 80
  • Thanks @Anik What If I would call a function that was defined out of it. 'app.service('CreateFactory',['customer',CreateFactory(customer)]);' Is this acceptable? If so how can I access a variable that was defined in **Address** service in CreateFactory Service. I am still learning AngularJs, sorry if I am wrong at anything. – Sudharshan Redyam Sep 21 '15 at 12:40
0

You just use the regular injection rules in Angular (following the convention for being able to minify your code):

app.service('service2',['service1', function(service1) {}]);
cullimorer
  • 755
  • 1
  • 5
  • 23
0

I am not using any square brackets for declaring in Angular, less bugs

app.service("customer", function(Address, Phone){
});

app.service('CreateFactory', function(customer){
});
Dmitri Algazin
  • 3,332
  • 27
  • 30