3

Why not able to inject '$scope' service in the service layer? If i add $scope inside the array, it brings the injection error.

app.service('LoginService', [ '$log', '$http', '$rootScope', '$scope', '$location', function($log, $http, $rootScope, $scope, $location) {
Suresh Palanisamy
  • 521
  • 1
  • 5
  • 13
  • 1
    you have a good explanation in this thread: http://stackoverflow.com/questions/22898927/injecting-scope-into-an-angular-service-function – CaptainMat Dec 11 '15 at 13:37

1 Answers1

4

Simply put, $scope is the scope of a controller which is bound to a view.

Services are singleton objects which contain or encapsulate reusable pieces of logic/functionality/code. Hence logically they do not have a scope at all. One can use variables in the services to set values/data and use or share it elsewhere.

Which is why its not allowed.

Temp O'rary
  • 5,366
  • 13
  • 49
  • 109