Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i followed the directions from this post:

Redirect using AngularJS

here is my user.js service:

'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;
    }
  };
}]);

i am running a python flask server for the app's API.

this piece of code executes fine when i have authenticated already:

user.success(function(resp) {
  console.log('SUCCESS! logged in!');
  d.resolve(resp.user);
});

however, when i have not authenticated and this piece of code executes:

user.error(function(resp) {
    console.log('not logged in!');
    var login_url = 'http://path/to/login/'
    scope.$apply(function() { $location.path(login_url); });
 });

i get this error:

Error: Unknown provider: $scopeProvider <- $scope <- user <- navigationDirective
share|improve this question
1  
Do you need a $ in front of scope.$apply(...) ? So $scope.$apply... –  Foo L Apr 26 '13 at 0:55
    
if i set the call to scope.apply i still get the err: Error: Unknown provider: $scopeProvider <- $scope <- user <- navigationDirective –  SeanPlusPlus Apr 26 '13 at 1:13
    
if i don't pass the $scope the function, i get this err: ReferenceError: scope is not defined –  SeanPlusPlus Apr 26 '13 at 1:14
1  
I meant for you to try $scope.$apply(..) . You might be missing the $ in front of scope.. –  Foo L Apr 26 '13 at 1:29
    
still errs out. –  SeanPlusPlus Apr 26 '13 at 1:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.