Reputation: 531
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) {
Upvotes: 3
Views: 79
Reputation: 5828
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.
Upvotes: 4