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();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With