logo
down
shadow

Angular UI Router issue when redirecting to a template after resolve() throws error


Angular UI Router issue when redirecting to a template after resolve() throws error

By : Kevin Verlinden
Date : November 22 2020, 01:01 AM
Hope this helps You need to call event.preventDefault() before you call $state.go().
See here: http://plnkr.co/edit/eUosIpdN7adJFxfDo3kV?p=preview
code :


Share : facebook icon twitter icon
How to handle error in angular-ui-router's resolve

How to handle error in angular-ui-router's resolve


By : user2455724
Date : March 29 2020, 07:55 AM
this one helps. The issue is that if any of the dependencies in the route resolve is rejected, the controller will not be instantiated. So you could convert the failure to data that you can detect in the instantiated controller.
Example Pseudocode:-
code :
   data: ["$q", "$timeout","$http", function ($q, $timeout, $http) {
      return $timeout(function () { //timeout already returns a promise
        //return "Yes";
        //return success of failure
         return success ? {status:true, data:data} : {status:false}; //return a status from here
       }, 2000);
     }]
 controller: ["$scope", "data", "$state", function ($scope, data, $state) {
      //If it has failed
      if(!data.status){
        $scope.error = "Some error";
       return;
      }
        $scope.detailvm = {
          state: $state.current.name,
          data: data
        };
resolve: {
        data: ["$q", "$timeout","$http", function ($q, $timeout, $http) {
           return $http.get("someurl")
             .then(function(){ return {status:true , data: "Yes"} }, 
                    function(){ return {status:false} }); //In case of failure catch it and return a valid data inorder for the controller to get instantated
        }]
      },
"use strict";

angular.module('MyApp', ["ui.router"]).config([
  "$stateProvider",
  "$urlRouterProvider",
  function ($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise("/item");
    $stateProvider
    .state("list", {
      url: "/item",
      template: '<div>{{error}}</div><div>{{listvm}}</div>' +
      	'<a ui-sref="list.detail({id:8})">go to child state and trigger resolve</a>' +
        '<ui-view />',
      controller: ["$scope", "$state", function($scope, $state){
       $scope.listvm = { state: $state.current.name };
      }]
    })
    .state("list.detail", {
      url: "/{id}",
      template: '<div>{{detailvm}}</div>',
      resolve: {
        data: ["$q", "$timeout","$http", function ($q, $timeout, $http) {
           return $http.get("/").then(function(){ return {status:true , data: "Yes"} }, function(){ return {status:false} })
        }]
      },
      controller: ["$scope", "data", "$state", function ($scope, data, $state) {
   
    
        $scope.detailvm = {
          state: $state.current.name,
          data: data.status ? data :"OOPS Error"
        };
        
      }]
    });
  }
]);
 <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
    <script data-require="angular-ui-router@*" data-semver="0.2.10" src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.10/angular-ui-router.js"></script>
  <div ng-app="MyApp">
      <ui-view></ui-view>
    </div>
Angular ui-router $state.go is not redirecting inside resolve

Angular ui-router $state.go is not redirecting inside resolve


By : user3333720
Date : March 29 2020, 07:55 AM
hope this fix your issue In my angularjs app, I am checking if user lands on landing page and is already authenticated, then redirect him to home page. , There can be two solutions to your problem
code :
$rootScope.$on('$stateChangeStart', function (event, toState) {      
     if (toState.name === 'landingpage') {              
       if (!isAuthenticated()) { // Check if user allowed to transition                  
            event.preventDefault();   // Prevent migration to default state                  
            $state.go('home.dashboard');           
        }
      }
});
Angular 1.5 - Ui-Router 1.0.0-beta.3 - No template configuration specified for 'resolve@root''

Angular 1.5 - Ui-Router 1.0.0-beta.3 - No template configuration specified for 'resolve@root''


By : David Lee
Date : March 29 2020, 07:55 AM
This might help you So I'm trying to get UI-Router's resolve method to work but I keep getting this error and I have not been successful in resolving this issue. Error: No template configuration specified for 'resolve@root' , Error is because of
code :
resolve: {
    communityId: ['backendFactoryService', function (backendFactoryService) {
        backendFactoryService....then(function (res) {
            return res;
        })
    }],
    brandingId: ['backendFactoryService', function (backendFactoryService) {
        // do stuff
        })
    }],
    community: ['backendFactoryService', function (backendFactoryService) {
               // do stuff 
        })
    }],
    branding: ['backendFactoryService', function (backendFactoryService) {

               // do stuff
        })
    }]
}
.state('root.home', {
  resolve: {
    communityId: ['backendFactoryService', function (backendFactoryService) {
        backendFactoryService....then(function (res) {
            return res;
        })
    }],
    brandingId: ['backendFactoryService', function (backendFactoryService) {
        // do stuff
        })
    }],
    community: ['backendFactoryService', function (backendFactoryService) {
               // do stuff 
        })
    }],
    branding: ['backendFactoryService', function (backendFactoryService) {

               // do stuff
        })
    }]
  },
  views: {
    'home@': {
      url: '/',
      templateUrl: 'src/survey/survey.template.html',
      controller: 'homeController',        
    }
  }
})
Angular js :-> angular throws unknown provider error while accessing resolve proprerty

Angular js :-> angular throws unknown provider error while accessing resolve proprerty


By : John A Maloney
Date : March 29 2020, 07:55 AM
wish helps you Dependencies added using resolve are injected as part of route being resolved and controller being created and are not available otherwise. These are not global dependencies like a service or filter.
If you use ng-controller the route transition does not happen and route related dependency resolution and controller creation does not take place and the DI error is raised.
Could not resolve '___' from state 'home' - angular ui-router issue

Could not resolve '___' from state 'home' - angular ui-router issue


By : Máté Borbély
Date : March 29 2020, 07:55 AM
Does that help Your code is not following the tutorial exactly. Note that for child states to function, they must reference their parent state.
In the tutorial code:
Related Posts Related Posts :
  • RangeError: Maximum call stack size exceeded with array.slice
  • node rest client get with local variable
  • If condition not executes while mouse move fastly
  • Count the number of displayed elements in a HTML list
  • Locate JavaScript source code in Emacs
  • Clean, Modular Code vs MV* Frameworks
  • infinite scroll without loading image
  • Backbone: reverse collection order with comparator
  • What do printers ignore?
  • jQuery UI .tabs() Contentless tab?
  • Execute Javascript alert() after page (visually) loaded
  • JavaScript - duplicating array doesn't work
  • Excessive clickable area below image
  • JavaScript Regex: Replace |b| with <b>
  • Unexpected value change in 2D array in JavaScript
  • Function doesnt see parameter as a array of objects
  • jQuery fetch keypress event on chrome and IE
  • How to enable jquery validate localization?
  • Cassandra map collection returned by node.js Helenus looks odd
  • angular ng-repeat with multiple filter options
  • Selecting Children without ID or Class names
  • How to uncheck a group of checkboxes when another checkbox is checked
  • Is hiding content by Javascript or jQuery Worth trying
  • Load XUL resource using javascript
  • XML to HTML text area from server file system
  • set focus() on textbox on form onload
  • es lint '' is assigned a value but never used' eventhough i have used it
  • Can "name" attribute be used for custom VueJS components
  • Get innerHTML of content when it is clicked
  • HTTPS causes CSS animations to not load? Very confused
  • How to hide other div apart from touched div to the band
  • Is global variable assignment atomic on NodeJS?
  • Datepicker onchangemonthyear beforeshowday
  • trying to render html files using jade but it still adresses it as a jade
  • Google Analytics - Understanding and Dissecting the Snippet: What is | | [ ];
  • Replacing "[aA09.b]." to "[aA09.b]\n" in in JavaScript
  • Why wrap a function definition in an immediate function?
  • Enable / disable jQuery script on switching to different tab in a HTML page
  • how can find return variable value outside anonymous function in node js mysql query function
  • Converting 1 to 0001 in javascript array
  • svg viewbox should not resize the text fontSize?
  • store newline character with string in a variable
  • MP4 videos in Flowplayer does not play in Windows 7 Chrome
  • jquery focusin event not firing
  • How to debug Vue application with google chrome
  • html 5 web app cache download complete javascript alert?
  • Ember.js setupController fired only once
  • How to validate a currency input
  • How to convert my Array of data to key & value pair
  • Statistics circles in CSS
  • So I wanted to make a trig solver in javascript?
  • Showing HighCharts series name on x-axis and in legend
  • In Rails, how can we pass parameters in script?
  • Build Fails: `npm rebuild node-sass --force`
  • Angular Datepicker change dateformat
  • Trying to extract data from between two sets of characters
  • Configuring Jest in WebStorm
  • Uncaught Error: Syntax error, unrecognized expression: tr.ec_portfolio_title,
  • JQuery fading in fading out continuously
  • Unexpected end of input (Line 1) and Undefined Function?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org