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

0 votes
How can i have condition on resolve result obtain trough web server??
Feb 11, 2020 in Angular by kartik
• 37,520 points
2,003 views

1 answer to this question.

0 votes

Hey, 

Let me consider that you have some service made available on clicking on button (assume multiply).

So you can have that routing making available through $routeProvider and can have condition on resolve result( Let me having condition that if my result is greater than 200 i will show error else show the result. To accomplished this follow the below code.

var app=angular.module('app',[;ngroute'])

app.config( [ '$routeProvider', function($routeProvider){

         $routeProvider.when('/calc/){

              template: <Strong> First Page</strong>

          $routeProvider.when('/calc/mult/:a/:b){

              template: "mult.html",

              controller: MultController,

             resolve:{

              multResult: function( $dataservice, $route,$q){

                   var a=$route.current.params.a;

                    var b=$route.current.params.b;

                   result.dataservice.multiply(a,b).then function(result){

                         if(result.data>200){

                            return $q.reject("Cannot have result");

                          }

                       else{

                           return result;

                         }

                       });

                 }

            }

 });

Hope, This is working for you now!!

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

Related Questions In Angular

0 votes
1 answer

Explain routing workflow with resolve in AngularJs?

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

answered Feb 10, 2020 in Angular by anonymous
• 82,840 points
1,157 views
0 votes
1 answer

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

$route is used for deep-linking URLs to controllers ...READ MORE

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

How do we work with UI-Router in AngularJS?

Hello @kartik,  As you know Ui-Router is more ...READ MORE

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

How can we specify no route path in UI-Router?

hey @kartik, In order to route to any ...READ MORE

answered Feb 11, 2020 in Angular by anonymous
• 82,840 points
1,239 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,840 points

edited Jan 21, 2020 by Niroj 1,143 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,840 points

edited Jan 21, 2020 by Niroj 1,206 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,770 points
119,702 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,840 points

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

How can we achieve transclusion in AngularJs?

Hii,  In order to know what transclusion is ...READ MORE

answered Feb 5, 2020 in Angular by Niroj
• 82,840 points
679 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,840 points
4,264 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