嗨,我想在成功登录后更改网址。登录url是localhost/filename/login.html,如果成功,则url是localhost/filename/index.html#/bird_eye。我使用的是angularjs 1.3.14。下面是app.js代码
var app = angular.module('cirqSignUp',
['cirq.controllers','cirq.services','ngRoute','ngStorage'])
app.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/login',{templateUrl: '/login.html', controller: 'login'})
.when('/birds_eye', {templateUrl: 'pages/birds_eye_view.html', controller: 'birdsEye',reloadOnSearch: false})
//.when('/analytics', {templateUrl: 'pages/analytics.html', controller: 'birdsEye'})
//.when('/items', {templateUrl: 'pages/listitems.html', controller: 'birdsEye'})
.when('/items/import_export', {templateUrl: 'pages/items/import_export.html', controller: 'importExport'})
.when('/items/categories', {templateUrl: 'pages/items/categories.html', controller: 'forCategory'})
//.otherwise({redirectTo: '/birds_eye'});
}])下面是控制器代码
.controller('login', ['$scope','$http','Services','$rootScope','$localStorage', '$sessionStorage','$location', function($scope,$http,Services,$rootScope,$localStorage, $sessionStorage,$location){
$('.error').hide();
$scope.loginRest = function(restLogin){
//
//alert(JSON.stringify(restLogin));
var request = Services.loginDashboard(restLogin);
request.success(function(res,status,headers,config){
alert(status);
//return
$localStorage.resDataRest = res.useremailid;
$localStorage.resTotalSales = res.dashBoard.todayssales;
$localStorage.resTotalTransct = res.dashBoard.todaystransactions;
console.log(JSON.stringify($rootScope.resDataRest));
$location.path('/birds_eye');
//afterLogin(res.useremailid);
//console.log($rootScope.resDataRest)
}).error(function(res,status,headers,config){
$scope.resMsg = res.responsemessage;
$('.error').show();
//alert(status);
});
};
//$rootScope.resDataRest = $scope.getVar;
/*function afterLogin(res){
$scope.data1 = res;
//$rootScope.afterLoginData = $scope.data1;
alert(JSON.stringify($scope.data1));
}*/}])
我使用$location面临的问题是url没有更新,也没有尝试使用windows.location,但是window.location的问题是我保存在作用域/根作用域变量中的response对象变得空值。请帮帮我
发布于 2016-04-02 01:54:13
来自$location文档:
更改浏览器的URL时,它不会导致重新加载整个页面。要在更改URL后重新加载页面,请使用较低级别的$window.location.href。
所以,试一试:
$window.location.href = '/birds_eye';https://stackoverflow.com/questions/36362670
复制相似问题