我現在有兩個視圖。
- 登錄
- 主要
現在我登錄並更改爲/main
的正常工作我的道路。當我沒有登錄,並嘗試訪問/main
我的網絡服務返回"Access denied for user anonymous"
然後我將它們轉發到/
這是我的登錄視圖。我怎麼能通過一些東西,所以我的LoginController
知道他們從/main
轉發,以提醒他們先登錄?
LoginController.js
VforumJS.controller('LoginController', function($scope, $location, $routeParams, LoginModel)
{
$scope.email = "";
$scope.password = "";
$scope.fetching = false;
$scope.error = null;
$scope.login = function()
{
$scope.error = null;
$scope.fetching = true;
LoginModel.login($scope.email, $scope.password);
}
$scope.$on('LoginComplete', function(event, args)
{
log('login complete: ' + args.result);
$scope.fetching = false;
if (args.result == "success")
{
$location.path('/main');
}
else
{
$scope.error = args.result;
}
});
});
MainController.js
VforumJS.controller('MainController', function($scope, $location, $routeParams, MainModel)
{
$scope.currentTitle = '-1';
$scope.presentationData = MainModel.getPresentations();
$scope.$on('PresentationsLoaded', function(event, args)
{
log(args.result);
if (args.result != "Access denied for user anonymous")
{
//-- Parse preso data
$scope.presentationData = args.result;
}
else
{
//-- Need to login first, route them back to login screen
$location.path("/");
}
});
});
非常好,使用$ location.search()爲我工作,謝謝。 – Ronnie