1

I want to add query params and hash to a url from controller without reloading the page.

var param [
    query: "abc",
    page : 1
];
$location.url("/project").search(param);

This changes the url from domainname.com to domainname.com/project?query=abc&page=1 which is fine but I also want to add div id to the url using hash. I want my url to be donainname.com/project?query=abc&page=1#result . How to achieve this any suggesstion or comments ? One thing should be taken care of that query params and hash should be added in one go as I have written a function which gets call when url changes otherwise it gets called more than once.

1 Answer 1

0

You can set it using $location.hash

$location.url("/project").search(param).hash('result');
Sign up to request clarification or add additional context in comments.

4 Comments

app.run( function($rootScope, $location, $http, $window) { $rootScope.$watch(function() { return $location.url(); }, function(a){ }); }); This function gets called when url changes, In your case it will call my function twice.
You can also set the url by hand using and redirect window.location, but then the page would reload, in case you're looking to avoid that.
ya I don't want to reload the page
could you host your code somewhere for help with debugging?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.