Reputation: 80385
I have a situation where I want the URL in the address bar to change, but I don't want Angular to refresh the controller or view like in a normal route change.
So, going to /data
then clicking on a link saying /data/just-blue
would only refresh a part of the ngView
not the entire view.
How is that possible?
Currently I have those 2 paths defined as separate .when()
paths in the app .config()
method.
Thanks.
Upvotes: 3
Views: 765
Reputation: 268
Here's another solution: http://joelsaupe.com/programming/angularjs-change-path-without-reloading/ (not using pushState)
Upvotes: 0
Reputation: 20348
So basically you can do the following:
$scope.$on("$locationChangeStart", function (event, next, current) {
console.log(event, next, current);
console.log(next);
if (next == 'http://localhost:9000/data/just-blue') {
setTimeout(function() {
$window.history.pushState("object or string",
"Title", '/data/just-blue)'},20);
event.preventDefault();
// ... update your view
}
});
Mind that I used setTimeout
instead of $timeout
.
Upvotes: 1