2015-10-06 49 views
0

我有一個關於在an​​gular.js.中重定向路徑的問題,我在下面解釋我的代碼。無法使用angular.js重定向到正確的路徑ui-router

profileController.js:

if($('#addProfileData')[0].defaultValue=='Update'){ 
      var updatedata={'colg_name':$scope.colgname,'address':$scope.address,'cont_no':$scope.contno,'profile_id':id}; 
      console.log('userupdate',userdata); 
      $http({ 
      method: 'POST', 
      url: "php/profile/updateProfileData.php", 
      data: updatedata, 
      headers: { 'Content-Type': 'application/x-www-form-urlencoded' } 
     }).then(function successCallback(response){ 
      alert(response.data); 
      $location.path('.profile'); 
     },function errorCallback(response) { 
      alert(response.data); 
     }); 
     } 
    } 

我在這裏設置路徑剖析成功回調內頁function.But被重定向到根頁面更新後的數據。

loginRoute.js:

var Admin=angular.module('Channabasavashwara',['ui.router']); 
Admin.config(function($stateProvider, $urlRouterProvider) { 
    $urlRouterProvider.otherwise('/'); 
    $stateProvider 
    .state('/', { 
      url: '/', 
      templateUrl: 'dashboardview/login.html', 
      controller: 'loginController' 
     }) 
     .state('dashboard', { 
      url: '/dashboard', 
      templateUrl: 'dashboardview/dashboard.html', 
      controller: 'dashboardController' 
     }) 
     .state('dashboard.profile', { 
     url: '/profile?p_i', 
     templateUrl: 'dashboardview/profile.html', 
     controller: 'profileController' 
    }) 
    .state('dashboard.dept', { 
     url: '/dept?d_i', 
     templateUrl: 'dashboardview/dept.html', 
     controller: 'deptController' 
    }) 
    .state('dashboard.princpal', { 
     url: '/princpal?pr_i', 
     templateUrl: 'dashboardview/princpal.html', 
     controller: 'princpalController' 
    }) 
    .state('dashboard.dept_head', { 
     url: '/dept_head?dh_i', 
     templateUrl: 'dashboardview/depthead.html', 
     controller: 'deptheadController' 
    }) 

}) 

這裏成功地被重定向更新數據的頁面之後的login.html page.I需要更新數據之後應該重定向到profile.html page.Please幫我。

回答

0

嘗試用$location.path('dashboard.profile'); 替代的代碼行會做必要爲你

+0

@ Lalit:不,我按你的意思添加,它不起作用。 – satya

0

您可以使用$狀態,而不是$位置如下:

$state.go('dashboard.profile') 

另外,不要忘記在控制器中注入$ state服務。

如果你想使用$ location.path,你需要使用url而不是狀態。

+0

@塔倫:我按你的方式做,但沒有改變方向。 – satya

+0

你會得到什麼錯誤? –

+0

@Tarun:沒有錯誤,但更新後頁面保持不變。 – satya

相關問題