V SH V SH - 3 years ago 84
AngularJS Question

How to set state parameter without reloading the Pagein Angular JS?

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.


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




.state('app.shine', {
url: '/showData',
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.

Answer Source

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 })
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download