Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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) {
like image 241
Suresh Palanisamy Avatar asked Aug 16 '26 00:08

Suresh Palanisamy


1 Answers

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.

like image 56
Temp O'rary Avatar answered Aug 19 '26 19:08

Temp O'rary



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!