Reputation: 711
I have a peculiar problem .I am using anchorScroll service to scroll the page to top to show any messages,like for error or save success messages. I am implementing the function in save button action.
What happens here that when I hit the button first time, it refreshes the page and then when I use it again ,I am getting the required result.
I would like to somehow stop it from refreshing the page first time around.
This button is outside the form directive,although my form is inside form tag. Included $anchorScroll service
<a id="top"></a> at the top of my HTML page.
if(data.validateError==true )
{
$scope.saveSuccessfull=false;
$scope.wrongInputError=true;
$scope.negErrorMessage=false;
$scope.loaderDiv=false;
$location.hash('top');
// call $anchorScroll()
$anchorScroll();
Upvotes: 4
Views: 6661
Reputation: 145
The reloadOnSearch: false solution suggested by @Raulucco worked fine for me. Following an example
$routeProvider
.when('/search', {
templateUrl : 'views/search.html', reloadOnSearch: false
})
Upvotes: 3
Reputation: 3426
I found this answer after having the same problem. I resolve it by creating a new service that makes the scroll with jQuery. but I found on the documentation that on the routeProvider is possible to set the attribute reloadOnSearch to false, so that now you can change the hash and the view won't reload. I found it a cleaner way.
Upvotes: 1
Reputation: 31192
From this answer : https://stackoverflow.com/a/15935517/971 which proved useful to me having a similar issue.
var old = $location.hash();
$location.hash('top');
$anchorScroll();
//reset to old to keep any additional routing logic from kicking in
$location.hash(old);
This will prevent the reload.
Upvotes: 14