1

I used dependency injections in my controllers as follows.

 .controller('deals_list', function ($scope, global, config, services, dealService, pagination) {

Now the app was growed. Dependencies are growing too. I want limit these injections. So is there a way to limit those with global injections or something?

What kind of procedure actually should I follow?

3
  • 1
    do you use all those services in that controller? if so, then they need to be injected. I find it unlikely that every controller has to use a global service, config service, and whatever the services service might be.... Commented May 16, 2015 at 4:10
  • I have several controllers for CRUDs. So I have to inject all services in each controllers. Commented May 16, 2015 at 4:30
  • maybe you can group them Commented May 16, 2015 at 4:34

2 Answers 2

2
var myApp= angular.module('myApp', []);

myApp.run(function ($rootScope, $location, $http, $timeout, YourService) {
    $rootScope.MyService = YourService;
}

Used it into controller :

myApp.controller('YouCtrl', ['$scope', function ($scope) { 
    // scope inherits from root scope
    $scope.MyService.doSomething();
}]);
Sign up to request clarification or add additional context in comments.

Comments

0

What i believe you can do is to create a service that contains all the services that you want to use. The global service is like a facade into your real service.

The option then are to create on global service with all dependencies included. Or multiple facade service which group these services

app.service("Configurations",function(global,config) {
  this.global=global;
  this.standard=config;
});

app.service("AppServices",function(services, dealService, pagination) {
  this.services=services;
  // other assigments
});

Now you can inject Configurations and AppServices

This at least gives some visibility into what your controllers are dependent upon.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.