3

How to make Angular.js to go to /route1 by default if the $rootScope.isAdmin==true, but if isAdmin is false or does not exist - go to /route2 ?

isAdmin is set in a login controller:

.controller(
  'LoginController',
['$scope', '$rootScope', '$http', 'authService',
  ($scope, $rootScope, $http, authService) ->
    $scope.submit = ->
      try
        $http.post("/users/sign_in",
          user:
            email: @username
            password: @password
            remember_me: if @remember_me then 1 else 0
        ).success (response) ->
          $rootScope.isAdmin = response[0].is_admin
          authService.loginConfirmed()
      catch ex
        alert ex
])
Paul
  • 25,812
  • 38
  • 124
  • 247
  • Are you looking for something more than $location.path(put_appropriate_route_here)? Or is that sufficient? – Mark Rajcok Feb 07 '13 at 21:45
  • Here is the similar question. http://stackoverflow.com/questions/14657711/redirect-index-page-if-user-is-logged-in-angularjs/14658126#14658126 – Jigar Patel Feb 10 '13 at 00:51
  • http://stackoverflow.com/questions/11541695/redirecting-to-a-certain-route-based-on-condition Try this. – Adam Harrison Feb 09 '16 at 20:50

0 Answers0