hi,
I have a problem with the provider in AngularJS. I would like to in any 
view to check whether the user is logged on. If not then it should redirect 
to / login. On the console, there is no error. I do not know what is wrong.

var app= angular.module("app", ["ngRoute", "ngAnimate", "ngResource"]);

app.config(["$routeProvider", "$locationProvider", function($routeProvider, 
$locationProvider) {
    var getItemNameById = function($route, $location, service, breadcrumbs, 
path) {
        service.getItem($route.current.params.id).then(function(evt) {
            if(evt.title) {
                $route.routes[path].label = evt.title;
            } else if(evt.name) {
                $route.routes[path].label = evt.name;
            }
            breadcrumbs.generateBreadcrumbs();
        }, function() {
            $location.path("/404");
        });
    };

    $routeProvider
        .when("/", {
            template: "",
            label: "Home",
            resolve: function($q, $location) {
                   alert("in resolve Home...");
                   var deferred = $q.defer(); 

                   if (!isLoggedIn) {
                        $location.path('/login');
                   }
                   deferred.resolve();
                   return deferred.promise;
            }
        })
        .when("/patient", {
            templateUrl: "patient.html",
            label: "Patient",
            resolve: function($q, $location) {
                   alert("in resolve Patient...");
                   var deferred = $q.defer(); 

                   if (!isLoggedIn) {
                        $location.path('/login');
                   }
                   deferred.resolve();
                   return deferred.promise;
            }
        })
        .when("/doctor", {
            templateUrl: "doctor.html",
            controller: "DoctorController",
            label: "Doctor",
            resolve: function($q, $location) {
                   alert("in resolve Home...");
                   var deferred = $q.defer(); 

                   if (!isLoggedIn) {
                        $location.path('/login');
                   }
                   deferred.resolve();
                   return deferred.promise;
            }
        });
}]);

app.run(["$rootScope", "LoginService", function($rootScope, LoginService) {
    $rootScope.$on("$routeChangeStart", function(event, nextRoute, 
currentRoute) {
      if (nextRoute != null ) {
           LoginService.checkSession().then(function(response) {
              $rootScope.isLoggedIn = response;
           }, function(reject) {
              $rootScope.isLoggedIn = reject;
           });   
      }   
    });
    

}]);


why not enter into sections resolve (alert also does not show) on the home 
page?

best regards

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to