SoFunction
Updated on 2025-04-08

Solve the problem of error in dependency injection of $scope in angularjs service

Console error message

:26794 Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- DutylogService
 /1.5.3/$injector/unpr?p0=<ion-nav-view name="tab-dutylog" class="view-container tab-content" nav-view="active" nav-view-transition="ios">copeProvider%20%3C-%20%24scope%20%3C-%20DutylogService
 at http://localhost:8100/lib/ionic/js/:13438:12
 at http://localhost:8100/lib/ionic/js/:17788:19
 at  [as get] (http://localhost:8100/lib/ionic/js/:17941:39)
 at http://localhost:8100/lib/ionic/js/:17793:45
 at getService (http://localhost:8100/lib/ionic/js/:17941:39)
 at injectionArgs (http://localhost:8100/lib/ionic/js/:17965:58)
 at  (http://localhost:8100/lib/ionic/js/:18007:18)
 at Object.<anonymous> (http://localhost:8100/lib/ionic/js/:17850:24)
 at  (http://localhost:8100/lib/ionic/js/:17995:19)
 at  [as $get] (http://localhost:8100/lib/ionic/js/:17834:37) 

reason:

('myModule', [])
.service('MyController', ['$scope', function($scope) {
 // This controller throws an unknown provider error because
 // a scope object cannot be injected into a service.
}]);

Suggested method:

.service('DutylogService', [function(){
 
}])

The above article solves the problem of $scope error in angularjs service. This is all the content I share with you. I hope you can give you a reference and I hope you can support me more.