0

I am using the state in Angular Js. I want to add some field like date in url without reloading the state. So I have seen related link AngularJS UI Router - change url without reloading state But I am still stuck in this problem.

HTML

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

CONTROLLER

$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: {
                  "content@app": {
                      templateUrl: 'view/view.html',
                      controller: 'controller'
                  }
              },

          })

I want to set $scope.startDate value in the URL as a state or query parameter. If I reload the page then These parameter should be there in URL , But these parameter should be set after click on the Apply button. I am new in the angular js. Please share your ideas. Thanks in advance.

onetwo12
  • 2,359
  • 5
  • 23
  • 34
Varun Sharma
  • 4,632
  • 13
  • 49
  • 103

1 Answers1

0

Make sure you are injecting $location into your controller, then you can use $location.search to update the url without a page refresh.

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

For example, I use something like this in one of my apps:

 this.$location.search({ key: this.linesQuery.order, id: this.lineIndex })
Mike Feltman
  • 5,160
  • 1
  • 17
  • 38