16180

get parent state from ui-router $stateChangeStart

Question:

I want to access the name of the parent state when detecting a statechange. My code so far:

<pre class="lang-Javascript prettyprint-override">app.run(function($rootScope, $state, authProvider) { $rootScope.$on("$stateChangeStart", function(event, toState, toParams, fromState, fromParams) { console.log(toState.name); }); });

Returns [parentState.childState]. One possibility would be to use regex to replace every symbole that comes after the "." but I guess there has to be a function in ui-router to get the name of the parent state.

What would I have to add? to get [parentState]?

Example: The user comes from the state login to the state pets.dogs. pets is an abstract parent state, dogs is a child of it. fromState.name would return login but I want pets.

EDIT: Yes, the workaround toState.name.split(".")[0] is possible but only works under controlled conditions.

Answer1:

I think you can do toState.parent.name.

Recommend

  • DataType float32 for attr 'T' not in list of allowed values: int32, int64
  • AngularJS UI-Router : Abstract state + child states not working
  • Testing event chains and module.run() in Angular + Jasmine
  • angular.js ui-route how catch route or url or params after reject?
  • integrate POCO library in android ndk
  • What is the best way to debug Bootstrap.groovy?
  • Android mkdirs() sdcard do not work
  • Mercurial: Identify file name after rename
  • Granting permissions to Azure Active Directory Web Application automatically
  • Why are “sc.addFile” and “spark-submit --files” not distributing a local file to all workers?
  • How can I let users share their location in Bot Framework webchat channel?
  • Dynamically load css stylesheet and wait for it to load
  • Converting query results into DataFrame in python
  • Access object instance inside an event handler
  • Cannot save model when using ember render helper
  • Android Database Error - getWriteableDatabase
  • Use tryCatch within R loop
  • How to use jQuery's $.post() method with async/await and typescript
  • TFS 2015 - Waiting for an agent to be requested
  • Detect when Facebook like button is clicked
  • Needing to do .toArray() to get output of mongodb .find() on key name not value
  • onBackPressed() not being executed
  • d3 v4 drag and drop with TypeScript
  • JQuery Internet Explorer and ajaxstop
  • Meteor: Do Something On Email Verification Confirmation
  • Q promise. Difference between .when and .then
  • Opengl-es onTouchEvents problem or a draw problem? [closed]
  • Volley JsonObjectRequest send headers in GET Request
  • Is there a amazon webstore API for customers?
  • How to get a value (ex: baseURL) in every Karate feature?
  • Fill an image in a square container while keeping aspect ratio
  • Perl system calls when running as another user using sudo
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • Upload files with Ajax and Jquery
  • Rearranging Cells in UITableView Bug & Saving Changes
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • AngularJs get employee from factory
  • Proper way to use connect-multiparty with express.js?
  • Linking SubReports Without LinkChild/LinkMaster
  • Reading document lines to the user (python)