嗨我想更改成功登錄時的網址。 登錄網址爲localhost/filename/login.html ,成功的url爲localhost/filename/index.html#/ birds_eye。我正在使用angularjs 1.3.14。 這裏是app.js代碼更改成功登錄後的url angularjs
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));
}
* /}])
我面對使用$位置的問題是該網址無法獲取更新和嘗試使用windows.location但window.location的問題是我保存在scope/rootscope變量中的響應對象變爲null。 請幫我
'Services.loginDashboard()'將返回一個'$ http'答應麼? – Malk
因爲這是一個使用'$ location.path('/ birds_eye')的SPA;''你需要在登錄後進入'localhost/filename /#/ birds_eye'。我有點擔心,因爲你在說url是'localhost/filename/index.html#/ birds_eye'。你在使用網絡服務器嗎?你在哪裏測試這個?你的服務呢? –
是的,我正在使用服務以及Web服務器。 index.html包含頁面的公共部分,這就是爲什麼url是這樣的。 – Prashanth