How to fix this error correctly?

Asked

Viewed 171 times

3

Error: [$injector:unpr] http://errors.angularjs.org/1.4.5/$injector/unpr?p0=%24scopeProvider%20%3C-%20%24scope%20%3C-%20LogUserService
at Error (native)
at http://localhost:8080/web/resources/js/angular/angular.min.js:6:416
at http://localhost:8080/web/resources/js/angular/angular.min.js:40:307
at Object.d [as get] (http://localhost:8080/web/resources/js/angular/angular.min.js:38:308)
at http://localhost:8080/web/resources/js/angular/angular.min.js:40:381
at d (http://localhost:8080/web/resources/js/angular/angular.min.js:38:308)
at e (http://localhost:8080/web/resources/js/angular/angular.min.js:39:64)
at Object.g.instantiate (http://localhost:8080/web/resources/js/angular/angular.min.js:39:213)
at Object.<anonymous> (http://localhost:8080/web/resources/js/angular/angular.min.js:39:501)
at Object.e [as invoke] (http://localhost:8080/web/resources/js/angular/angular.min.js:39:96)

2 answers

3


A good tip is to always access the links that the angle generates when it points out that an error occurred.

For example http://errors.angularjs.org/1.4.5/$injector/unpr? P0=%24scopeProvider%20%3C-%20%24scope%20%3C-%20LogUserService

The angular itself is already telling you the problem and still giving the answer when you access the link.

Unknown Provider: $scopeProvider <- $Scope <- Loguserservice

He was unable to locate the dependency on his Loguserservice controller to inject into it.

Make sure you created the Service and imported the javascript file where it was created.

Also make sure you’re injecting $Scope service into your controller.

The angular works mainly with dependency injection and this causes it by not locating a dependency of its controller to break the application exactly to prevent access to non explicit resources.

Questions about this, from a google search on Dependency Injection.

  • Erick did dependency injection exactly as he says it should be done but even so he keeps giving this error, you know some way to perform a debug to check exactly the problems?

  • @Can Victor post your controller code and the part of your HTML where you import Java? Either way, you can install the Angularjs Batarang (stable) version extension on Chrome to help you. It only works on Chrome.

  • Hello Erick, I discovered what the error was, I was putting in service the parameter $Cope, and looking at the documentation that a servioce can not depend on $Scope

2

You’re trying to use $scope, but the qaue function defines your controller or similar is not referencing $scope for injection. Something similar to this:

angular.module('myApp', [])
.controller('MyController', [function () {
    $scope.varContent = true; // Erro: $scope está faltando
}]);

Pass the reference, like this:

angular.module('myApp', [])
.controller('MyController', ['$scope', function ($scope) {
  // Do something with myService
}]);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.