2015-07-11 52 views
0

現在我有差異模塊中的菜單指令和產品頁面。如何爲每次點擊刷新路線,而不是改變路線?

這裏類似的菜單

<ul class="nav navbar-nav" > 
    <li class="active"> 
    <a href="#/product">Products</a> 
    </li> 
</ul> 

這裏同類產品控制器

.controller('ProductCtrl', ['$scope','flash','$http','FileUploader','$filter','$cookieStore', function ($scope,flash,$http,FileUploader,$filter,cookie) { 
$scope.$on('$routeChangeSuccess', function(angularEvent, current, previous) { 
    if ('new_id' in current.params){ 
      $scope.product_id = current.params.new_id; 
      $http.get('/v2/oauth/product/'+current.params.new_id).success(function(data,state,headers,config){ 
       if(state==200){ 
        $scope.product_id = data.answer._id; 
        setProduct_variable(data.answer); 
        flash('Get Product info:'+data.answer['name']); 
       } 
      }) 
    }else{ 
     $http.post('/v2/oauth/product/new').success(function(data,state,headers,config) { 
      if (state ==200){$scope.product_id =data} 
     }); 
     flash('Get new Product Id!'); 
    } 
    //console.log(current.params); 
}); 
}]) 

,這裏是routeProvider配置

$routeProvider.when('/product',{templateUrl:'/view/product',controller:'ProductCtrl'}); 

改變路線是success.but我需要重裝產品在#/產品或需要寫一個事件來獲取產品ID和每次點擊#清潔變量/產品

在此先感謝

回答

0

試試這個:

$route.reload(); 

從手冊:

https://docs.angularjs.org/api/ngRoute/service/ $路線

您還需要注入$途徑進入你的控制器。

+0

我知道,,但我已經美元$範圍。在$(「$ routeChangeSuccess」)..並在那裏寫 –

+0

我需要正確的位置寫code..event或其他? –

+0

內,您的$ routeChangeSuccess事件。檢查新的ID是否與當前的作用域ID匹配,如果沒有,則重新加載。 – geoidesic