2016-04-01 15 views
1

Merhaba Başarılı oturum açmada URL'yi değiştirmek istiyorum. Oturum açma URL'si localhost/dosyaadı/login.html ve başarılı olduğunda url, localhost/filename/index.html #/birds_eye şeklindedir. Angularjs 1.3.14 kullanıyorum. İşte app.js koduBaşarılı girişte url'yi değiştir 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'}); 
}]) 

ve burada kontrolör kodunu

.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)); 
} 

olduğunu * /}])

i $ konumu kullanarak karşıya sorun url almıyor olduğunu windows.location kullanarak güncellenen ve denedim ama window.location ile problemi bir kapsamda kaydettiğim cevap nesnesi/rootscope değişkenine null'ed oluyor. $location doc itibaren bana

+0

'Services.loginDashboard()' Bir '$ http' söz dönüyor? – Malk

+0

Bu, '$ location.path ('/ birds_eye') kullanan bir SPA olduğundan, oturum açtıktan sonra' 'localhost/filename/#/birds_eye' 'ye gitmeniz gereken tek şey. Biraz endişeliyim çünkü url, localhost/dosyaadı/index.html #/birds_eye' şeklindedir. Bir web sunucusu kullanıyor musunuz? Bunu nerede test ediyorsunuz? Hizmetin ne olacak? –

+0

evet bir servisin yanı sıra bir web sunucusu kullanıyorum. Index.html sayfanın ortak bölümünü içerir, bu nedenle URL böyle bir şeydir. – Prashanth

cevap

0

yardım edin: tarayıcı URL değiştiğinde Bu tam sayfa yeniden yüklenmesini neden olmaz

. URL'yi değiştirdikten sonra sayfayı yeniden yüklemek için alt düzey API, $ window.location.href dosyasını kullanın.

yüzden, deneyin:

$window.location.href = '/birds_eye'; 
+0

ama $ konum kullanırken index.html #/birds_eye? – Prashanth

+0

için change.htm değiştirecek tüm localstorage değişkenleri undefined oluyor. – Prashanth

İlgili konular