【发布时间】:2016-12-27 11:23:44
【问题描述】:
我正在编写一个使用 ngRoute 来更改页面的网站。 用于登录的表单将出现,当它成功时,控制器会在接下来的步骤中更改请求的 http 标头。 问题是当我更改标题时,如果没有重新加载页面,则不会将令牌添加到标题中。
控制器:
app.controller('catCtrl',['Api','$scope','$cookieStore','$rootScope',function (Api,$scope,$cookieStore,$rootScope) {
$scope.Login = function(){
Api.loginEmail($scope.log_email, $scope.pass, 'chrome', 'windows','').success(function(response){
$cookieStore.put('Auth-Key', 'Token ' + response.token);
$scope.is_Loggedin = true;
$scope.showLoginWin();
}).error(function(response){
$scope.log_email = null;
$scope.pass = null;
$scope.error = response.error;
});
};
}
应用程序运行:
app.run(['$cookieStore','$http',function($cookieStore, $http){
$http.defaults.headers.common['Authorization'] = $cookieStore.get('Auth-Key');
}]);
如何在不重新加载页面的情况下更改标题。
【问题讨论】:
标签: javascript angularjs http cookies