Although you enter $rootScope and ngDialog , you still need to list them in your service.
var myservice= function($rootScope, ngDialog) { // ... } myservice.$inject = ['$rootScope', 'ngDialog']; someModule.service('myservice', myservice);
Update: this code works great
var myservice = function($rootScope,ngDialog) { alert($rootScope); } angular.module('myapp',['ngDialog']).controller('datac',function($scope,myservice){ $scope.parties = []; myservice.$inject = ['$rootScope','ngDialog']; }); angular.module('myapp').service('myservice', myservice);
Here is the plunker link: http://plnkr.co/edit/FXrE3jNhAYqtv7vVGzgx?p=preview
Update: Okay, sorry I injected the service into the controller instead of just injecting rootScope and ngDialog into the service outside the controller
var myservice = function(obscope,obdialog) { alert(obscope); } myservice['$inject'] = ['$rootScope', 'ngDialog']; angular.module('myapp',['ngDialog']).controller('datac',function($scope,myservice){ $scope.parties = []; }); angular.module('myapp').service('myservice', myservice);
source share