Is automatic dependency injection available in AngularJS?

I want automatic dependency to embed the Angular built-in service in all services in the Angular module / application.

The service I want to enter is ... $ exceptionHandler

I do not want $ exceptionHandler to be global ... for example. I do not want to do ...

window.$exceptionHandler = $exceptionHandler

But I also don't want the $ exceptionHandler injection in each service to hang manually, using ...

angular.module('myApp').factory('myService', ['$exceptionHandler', function ($exceptionHandler) {

Is it possible to automatically embed the built-in Angular service in all services in the Angular / <module? >

Many thanks

+4
source share
1 answer

. ( ) $exceptionHandler , . $exceptionHandler, . $exceptionHandler factory, , .

:

app.js

angular.module('app', ['ionic', '$exceptionHandler', 'ngCordova','app.home',
'app.impressum'])

.run(function ($ionicPlatform, $state) {
   ..
})
.config(function ($stateProvider, $urlRouterProvider, $provide, $exceptionHandler, $ionicConfigProvider, $compileProvider) {

    $stateProvider
        .state('app', {
            ...
        })
    }
);

app.home:

home.js

angular.module('app.home', ['app.home.controller', 'app.home.factory']);

/controller.js

angular.module('app.home.controller', [])
  .controller('homeController', function ($scope, $exceptionHandler) {
    ...
  });

app.home.factory app.impressum , .

, $exceptionHandler , , app.home app.

AngularJS, , ... , . , .

+3

Source: https://habr.com/ru/post/1568739/


All Articles