Angular.js中的条件默认路由

时间:2013-02-07 18:58:39

标签: routes angularjs

如果$ rootScope.isAdmin == true,如何使Angular.js默认转到/ route1,但如果isAdmin为false或不存在 - 请转到/ route2?

isAdmin在登录控制器中设置:

.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
])

0 个答案:

没有答案