How can we go back to previous page after having some error on request made through current page

0 votes
I'm having a web page that contains multiply button but i have a condition that if result is more than 200 i should go back to previous page after displaying the message that " Result cannot be more than 200" .How can i do that?
Feb 11, 2020 in Angular by kartik
• 37,510 points
988 views

1 answer to this question.

0 votes

$route is used for deep-linking URLs to controllers and views (HTML partials). It watches $location.url() and tries to map the path to an existing route definition.

The Event which are available in $route service are:

  • $routeChangestart
  • $routeChangeSuccess
  • $routeChangeError
  • $routeChangeUpdate
  • $locationChangeStart
  • $locationChangeSuccess

In order to consume the above mentioned event use app.run() which will execute once's app is ready to run.

So there is Event provided in $route  of  $routeChangeError  you can make use of that to obtain your desired result.

 The following is the basic syntax that must be include to use events:

app.run(['$rootScope, function($rootScope){

    $rootScope.$on($routeChangestart , function( e, curr, prev){
          console.log(' In $routeChangestart');
          });
    $rootScope.$on($routeChangeSuccess, function( e, curr, prev){
         console.log(' In $routeChangeSuccess');
         });      

     $rootScope.$on($routeChangeError, function( e, curr, prev , rejection){
         console.log(' In $routeChangeError- msg:' +rejection);


          $rootscope.isLoading=false;

          if(curr.$$route.originalp.path=="/calc/mult/:a/:b"){

             $window.history.back();}
         });
}]);

 The most important part of the code is $window.history.back(). This tell the markup if there is an error go back to the previous navigated page from browser history

answered Feb 11, 2020 by Niroj
• 82,880 points

Related Questions In Angular

0 votes
1 answer

How can we redirect to an existing route using ngRoute?

Routing is just another way of fixing some content ...READ MORE

answered Feb 6, 2020 in Angular by Niroj
• 82,880 points
3,281 views
0 votes
1 answer

How can we display message when we click some element(button) that server is loading?

hey kartik,  As $route is used for deep-linking URLs ...READ MORE

answered Feb 11, 2020 in Angular by Niroj
• 82,880 points
4,050 views
0 votes
1 answer

How can we provide condition based on certain resolve result obtained in routing with resolve?

Hey,  Let me consider that you have some ...READ MORE

answered Feb 11, 2020 in Angular by Niroj
• 82,880 points
1,737 views
0 votes
1 answer

How to set focus on an input field after rendering?

Hello @kartik, You should do it in componentDidMount and refs callback instead. ...READ MORE

answered Jul 22, 2020 in Angular by Niroj
• 82,880 points
1,670 views
+1 vote
1 answer

What is the relationship between angularjs Scope with controller/view?

Let us consider the below block: <div ng-controller="emp"> ...READ MORE

answered Jan 20, 2020 in Web Development by Niroj
• 82,880 points

edited Jan 21, 2020 by Niroj 803 views
+1 vote
1 answer

What is css box module?

Hey, All the element present in html follows ...READ MORE

answered Jan 20, 2020 in Web Development by Niroj
• 82,880 points

edited Jan 21, 2020 by Niroj 974 views
0 votes
3 answers

Explain the difference between visibility:hidden; and display:none?

display:none means that the tag in question will ...READ MORE

answered Dec 14, 2020 in Web Development by Gitika
• 65,910 points
118,532 views
+1 vote
1 answer

How to access the Angularjs scope of a particular html element from our console?

Hello, You should follow the below steps:-- 1.Compile and ...READ MORE

answered Jan 21, 2020 in Web Development by Niroj
• 82,880 points

edited Jan 21, 2020 by Niroj 2,478 views
0 votes
1 answer

How can we redirect to another page from existing page on clicking alert?

hii, It is really simple to redirect from ...READ MORE

answered Feb 6, 2020 in Angular by Niroj
• 82,880 points
3,862 views
0 votes
1 answer

How can we reload a page after requesting the same get parameter using AngularJS?

hey kartik, The reason for this is that ...READ MORE

answered Feb 10, 2020 in Angular by Niroj
• 82,880 points
12,257 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP