"inconnu fournisseur de l'erreur Angulaire app

J'ai suivi l'angle de docs pour créer mon Service et j'ai vu un message d'erreur

http://docs.angularjs.org/error/$injector:unpr?p0=$scopeProvider%20%3C-%20$scope%20%3C-%20$users

C'est mon code:

var angularApp = angular.module("myApp", []);
angularApp.run(function($http) {
$http.defaults.headers.common['Content-Type'] = 'application/x-www-form-urlencoded';
$http.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
});
angularApp.service('$users', function($scope, $http, $cookie, $window) {
//need to instantiate the service
var newUsersServiceInstance;
//upper case is resource
var User = $resource('/user/:userId', {userId:'@id'});
var MyPassword = $resource('/mypasswords/new');
//lower case is instance you tend to want the instance
//to be binded to the controller's scope
$scope.user //= User.get({userId:123});
$scope.getUser = function(id, s) {
$scope.user = User.get({"userId": id}, s, e);
}
$scope.changePassword = function(data, s, e) {
MyPassword.post(data, s, e);
}
//need to return the instance
return newUsersServiceInstance;
});
angularApp.controller('passwordController', ['$scope', '$users', function($scope, $users) {
$scope.changePasswordForm = function() {
$users.changePassword(
$.param($scope.data),
function(data, xhr) {
console.log(data);
},
function(data, xhr) {
console.log(data);
//error callback
$scope.errors = data.errors;
})
}
$scope.debug = function () {
console.log($scope);
}
}]);

Je ne suis pas sûr de l'endroit où je suis allé mal.

Mon nouveau code, après prise en compte de tout le monde de réponse. Même erreur.

var angularApp = angular.module("myApp", []);
angularApp.run(function($http) {
$http.defaults.headers.common['Content-Type'] = 'application/x-www-form-urlencoded';
$http.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
});
angularApp.service('$users', function($http, $cookie, $window) {
//upper case is resource
var User = $resource('/user/:userId', {userId:'@id'});
var MyPassword = $resource('/mypasswords/new');
//lower case is instance you tend to want the instance
//to be binded to the controller's scope
this.user //= User.get({userId:123});
this.getUser = function(id, s) {
this.user = User.get({"userId": id}, s, e);
}
this.changePassword = function(data, s, e) {
MyPassword.post(data, s, e);
}
return this;
});
angularApp.controller('passwordController', ['$scope', '$users', function($scope, $users) {
$scope.changePasswordForm = function() {
$users.changePassword(
$.param($scope.data),
function(data, xhr) {
console.log(data);
},
function(data, xhr) {
console.log(data);
//error callback
$scope.errors = data.errors;
})
}
$scope.debug = function () {
console.log($scope);
}
}]);

Même après le passage à l'utilisation de l'usine, je vois les mêmes erreurs.

var angularApp = angular.module("myApp", []);
angularApp.run(function($http) {
$http.defaults.headers.common['Content-Type'] = 'application/x-www-form-urlencoded';
$http.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
});
angularApp.factory('$users', function($resource, $http, $cookie, $window) {
//need to instantiate the service
var newUsersServiceInstance = {};
//upper case is resource
var User = $resource('/user/:userId', {userId:'@id'});
var MyPassword = $resource('/mypasswords/new');
//lower case is instance you tend to want the instance
//to be binded to the controller's scope
newUsersServiceInstance.user //= User.get({userId:123});
newUsersServiceInstance.getUser = function(id, s) {
newUsersServiceInstance.user = User.get({"userId": id}, s, e);
}
newUsersServiceInstance.changePassword = function(data, s, e) {
MyPassword.post(data, s, e);
}
//need to return the instance
return newUsersServiceInstance;
});
angularApp.controller('passwordController', ['$scope', '$users', function($scope, $users) {
$scope.changePasswordForm = function() {
$users.changePassword(
$.param($scope.data),
function(data, xhr) {
console.log(data);
},
function(data, xhr) {
console.log(data);
//error callback
$scope.errors = data.errors;
})
}
$scope.debug = function () {
console.log($scope);
}
}]);
  • Êtes-vous de vider votre cache, après tout, de la mise à jour il n'y a aucun moyen que vous pouvez obtenir le $scopeProvider erreur, $scope n'est pas référencé plus.
  • perdre $cookie...
  • Vous avez raison. Il est maintenant de$cookieProvider erreur. Désolé. J'ai supprimé les $cookie $et fenêtre. Il fonctionne maintenant
  • Merci à vous, @TheSharpieOne
InformationsquelleAutor Kim Stacks | 2014-01-19