2017-07-26 27 views
0

我正在使用Angular Js中的狀態。我想在url中添加一些像日期這樣的字段,而無需重新加載狀態。所以我看到相關鏈接AngularJS UI Router - change url without reloading state 但我仍然陷在這個問題中。如何在不重載Pagein Angular JS的情況下設置狀態參數?

HTML

<button class="btn btn-md btn-primary" ng-click="dumy()">Apply</button> 

控制器

$scope.dumy=function(){ 
    $scope.startDate="2017-07-26T09:30:00Z";  
    $scope.endDate="2017-07-26T18:30:00Z";  
} 

MODEL.JS

.state('app.shine', { 
       url: '/showData', 
       params:{ 
       View:null, 
       Edit:null, 
       Enable:null, 
       Delete:null 
       },    
       views: { 
        "[email protected]": { 
         templateUrl: 'view/view.html', 
         controller: 'controller' 
        } 
       }, 

      }) 

我想設置$ scope.startDate將URL中的值作爲狀態或查詢參數。如果我重新加載頁面,那麼這些參數應該在URL中,但是這些參數應該在點擊應用按鈕後設置。我是新的角js。請分享你的想法。提前致謝。

回答

0

請確保您將$ location注入到您的控制器中,然後您可以使用$ location.search更新網址而不刷新頁面。

$location.search({ object with query parameter values }) 

例如,我用我的應用程序之一是這樣的:

this.$location.search({ key: this.linesQuery.order, id: this.lineIndex }) 
+0

@麥克Feltman我怎麼能在控制器再次得到這個鍵值? –

+0

var search = $ location.search()會返回一個像上面那樣的對象。它基本上解析了一切後面的事情?在URL中加入一個對象。 –

+0

非常感謝Mike Feltman。 –

相關問題