Suresh Palanisamy
Suresh Palanisamy

Reputation: 531

Service injection error in angular app

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

Answers (1)

Temp O'rary
Temp O'rary

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

Related Questions