我按照这篇文章的指示:
这是我的user.js服务:
'use strict';
staticApp.factory('user', ['$scope', '$http', '$q', '$location', function ($scope, $http, $q, $location) {
$http.defaults.useXDomain = true;
var host = 'http://' + window.location.hostname + ':5001';
return {
current: function() {
var d = $q.defer();
var user = $http({method: 'GET', url: host + '/api/user.json'});
user.success(function(resp) {
console.log('SUCCESS! logged in!');
d.resolve(resp.user);
});
user.error(function(resp) {
console.log('not logged in!');
var login_url = 'http://path/to/login/';
scope.$apply(function() { $location.path(login_url); });
});
return d.promise;
}
};
}]);
我正在运行应用程序API的python flask服务器。
这段代码在我已经过身份验证后执行正常:
user.success(function(resp) {
console.log('SUCCESS! logged in!');
d.resolve(resp.user);
});
然而,当我没有经过身份验证并执行这段代码时:
user.error(function(resp) {
console.log('not logged in!');
var login_url = 'http://path/to/login/'
scope.$apply(function() { $location.path(login_url); });
});
我收到此错误:
Error: Unknown provider: $scopeProvider <- $scope <- user <- navigationDirective