[英]Redirecting using $location upon successful login with Angular
I have an Angular service that handles logging in to my SPA. 我有一个处理登录到SPA的Angular服务。
myApp.service('loginService', ['$rootScope', '$http', '$resource', '$cookies', '$location', function($rootScope, $http, $resource, $cookies, $location) { this.validateEmail = function() { $http({ url: myAppConfig.rootAPIUrl + 'Authenticate', params: { "playerId": $rootScope.data.emailId, "emailAddress": $rootScope.data.emailAddress }, method: "POST" }) .then(function(response) { if (response.data.Message == 'Success') { console.log('Login is successful.'); $cookies.put('emailId', $rootScope.data.emailId); $location.path("#/game").replace(); } $rootScope.msg = response.data; console.log(response.data); }, function(response) { console.log('Error in $http in controller...'); }); } }]);
Upon successful login, my conditions check out in the if block, I get the console msg, I get my cookie set, but the setting of the location path to '#/game' doesn't work. 成功登录后,我的条件在if块中签出,我得到了控制台味精,得到了cookie集,但是位置路径设置为“#/ game”不起作用。 Any ideas on why?
有什么想法吗?
You just need to pass '/game'
in the $location.path
. 您只需要在
$location.path
传递'/game'
。 That's how it works for me. 这就是我的工作方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.