Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page refresh issue in angularjs

Tags:

angularjs

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();
like image 739
Vikash Avatar asked Dec 02 '22 17:12

Vikash


1 Answers

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.

like image 177
mathieu Avatar answered Dec 11 '22 00:12

mathieu