javascriptangularjsangular-routingui-sref

cannot resolve state angularjs


I'm getting an error when trying to go from one state in my app to another one.

I have in an index file all my states defined.

index.js

var MyModule = angular.module('myApp.ui.moduleTest', [
  'ui.router'
])
.config(function($stateProvider, modalStateProvider){
  $stateProvider

    .state('myApp.dashboard.appArea.moduleTest',
      modalStateProvider.create({
        animation: true,
        name: 'myApp.dashboard.appArea.moduleTest',
        url: 'apps/moduleTest',
        controllerAs: 'moduleTestCtrl',
        controller: 'ModuleTestCtrl',
        windowClass: 'semi-modal semi-modal--huge',
        templateUrl: function() {
          return 'app/ui/apps/moduleTest/widget.html';
        },
        resolve: {
          //Some function to retrieve data
        }
      })
    )
    .state('myApp.dashboard.appArea.moduleTest.wizards',
      modalStateProvider.create({
        animation: true,
        name: 'myApp.dashboard.appArea.moduleTest.wizards',
        url: 'apps/moduleTest/runWizard',
        controllerAs: 'moduleTestWizardCtrl',
        controller: 'ModuleTestWizardCtrl',
        templateUrl: function(){
          return 'app/ui/apps/moduleTest/wizard.html';
        }
        // resolve: {
        //
        // }
      })
    )
})

When I'm in state "myApp.dashboard.appArea.moduleTest" Fron ModuleTestCtrl I'm trying to go to the state "myApp.dashboard.appArea.moduleTest.wizards" But I get the error "could not resolve state". How can I import this config module inside my controller in order to navigate to that state?

/*jslint node: true */
'use strict';

var angular = require('angular');

function ModuleTestCtrl($uibModalInstance, Api, diagnosticsRaw,  myService, $state) {

  this.$uibModalInstance = $uibModalInstance;
  this.Api = Api;
  this.dataRaw = diagnosticsRaw;

  this.parserData = function(indexes) {
      //Some app logic irrelevant
  }

  myService.setPropertyToRun(this.dataRaw);
  myService.setIsPropertyToRun(true);

$state.go('myApp.dashboard.appArea.moduleTest.wizards'); //THIS IS WHERE I HAVE MY PROBLEM

  };
}

ModuleTestCtrl.$inject = ['$uibModalInstance', 'Api', 'diagnosticsRaw', 'myService', '$state']; module.exports = ModuleTestCtrl;


Solution

  • Have you described all parent states of myApp.dashboard.appArea.moduleTest and myApp.dashboard.appArea.moduleTest.wizards in your angular.config, if not that could be the problem.

    Example:
    wizards is a child of moduleTest which is a child of appArea which is a child of dashboard which is a child of myApp, you get the point. You first need to have declared all these parent states even though they might not do anything.

    More about ui-state at:
    https://github.com/angular-ui/ui-router/wiki/Nested-States-and-Nested-Views