In my AngularJS project, I have a form having searching filter. What I do is I can select filters and then click on Search button. It gives me a list of search results. From that search result, I have a button from which I can navigate to another page. Now if I click on "Browser back button", it reloads the first page completely without having my search results- just like a fresh reload of page.
Is there any way so I can change the URL of first page along with query string when I click on Search button and be there on the same page without changing the controller and view ?
Here is my piece of code:
View page:
<div>
<select class="form-control" ng-options="producttype.Name></select>
</div>
<div>
<button type="submit" class="btn btn-primary" ng-click="search()">
Search
</button>
</div>
In Controller:
$scope.search = function () {
// Search method to get results
}
The page's url is #/Product.
Config page is :
app.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when('/Product',
{
controller: 'ProductController',
templateUrl: '/app/product.html'
})
I want to make it change to #/Product?ProductType=".." when user click on Search button on the same page. I referred link1 and link2 but did not get it. Any suggestions how can I achieve this ? Thanks.