Laurynas
Laurynas

Reputation: 1032

AngularJS $location.search do not reload page

As my title says, $location.search do not reload page, it just updates the URL. My code:

var app = angular.module('myApp', [], function($locationProvider) {
        $locationProvider.html5Mode(true);
    });
    app.controller('mytableCtrl', function($scope, $location, $http) {
        $scope.target = $location.search()["categoryid"];
        $http.get("api/topCategories")
        .success(function(response) {$scope.names = response;});                        
    }); 

Any suggestions? Are there any alternative for this code?

Edit: $location.search search for parameter in category.html?categoryid=any_number . It takes any_number number and has to compare it with another value. However, I try to press any a href it just updates the URL, but not reloads page.

Upvotes: 1

Views: 1632

Answers (2)

Laurynas
Laurynas

Reputation: 1032

I just added target="_self" in a href tags and it works perfectly.

Upvotes: 1

jeronimo vallelunga
jeronimo vallelunga

Reputation: 204

If you want to reload the page you have to use:

var categoryid = 1;
$window.location.href = '/index.html/#' + $location.path() + '?categoryid=' + categoryid;

Note: Do not forget to include $window to your controller

But, if you want to change your path, without reload the hold page, simply

var categoryid = 1;
$location.path('/some/new/path' + '?categoryid=' + categoryid);

This action will evaluate the ngRoute, and keeps app information as it is.

Upvotes: 0

Related Questions