Hello,
Can someone educate me on why the order of injection matters? I’ve been reading up on how dependency injection works in Angular and the official documents state that DI’s are not position based but name based.
My problem is that in my code, where I put the DI seems to matter.
Consider for example this code in app.js
.constant('zm', {
httpTimeout:15000,
largeHttpTimeout:60000,
logFile:'zmNinjaLog.txt',
// followed by other constants
})
Now in my controller that needs these constants:
This works - note the ‘zm’ position
angular.module(‘zmApp.controllers’).controller(‘zmApp.MontageCtrl’, [‘$scope’, ‘$rootScope’, ‘zm’, ‘ZMDataModel’, ‘message’, ‘$ionicSideMenuDelegate’, ‘$timeout’, ‘$interval’, ‘$ionicModal’, ‘$ionicLoading’, ‘$http’, ‘$state’, ‘$ionicPopup’, ‘$stateParams’, ‘$ionicHistory’, ‘$ionicScrollDelegate’, ‘$ionicPlatform’,function ($scope, $rootScope, zm, ZMDataModel, message, $ionicSideMenuDelegate, $timeout, $interval, $ionicModal, $ionicLoading, $http, $state, $ionicPopup, $stateParams, $ionicHistory, $ionicScrollDelegate) {
But doing this results in all the constants showing up as undefined
angular.module(‘zmApp.controllers’).controller(‘zmApp.MontageCtrl’, [‘$scope’, ‘$rootScope’, ‘ZMDataModel’, ‘message’, ‘$ionicSideMenuDelegate’, ‘$timeout’, ‘$interval’, ‘$ionicModal’, ‘$ionicLoading’, ‘$http’, ‘$state’, ‘$ionicPopup’, ‘$stateParams’, ‘$ionicHistory’, ‘$ionicScrollDelegate’, ‘$ionicPlatform’,‘zm’,function ($scope, $rootScope, ZMDataModel, message, $ionicSideMenuDelegate, $timeout, $interval, $ionicModal, $ionicLoading, $http, $state, $ionicPopup, $stateParams, $ionicHistory, $ionicScrollDelegate,zm ) {
Can someone help me understand:
a) Why this happens
b) How do I debug such situations to know if a DI is injected properly or not?
As my code is growing, I am trying to make sure I get all these things sorted out.