question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Notify: false prevents state transition entirely (not just events)

See original GitHub issue

Hi,

I’ve created a Plunker here

As shown in the example I think one would expect to be able to use event.preventDefault() in the $stateChangeStart event to prevent a transition, then later trigger that same transition manually with {notify: false} to prevent the event being triggered and therefore the state transition being blocked again (infinite loop).

However the viewDirective is relying on $stateChangeSuccess internally which is also prevented by {notify: false}.

One work around is like so:

$state.go(toState.name, toParams, {notify: false}).then(function() {
    $rootScope.$broadcast('$stateChangeSuccess', toState, toParams, fromState, fromParams);
});

I think perhaps the best solution here would be to use an alternative event internally to trigger the updateView() in viewDirective, or alternatively extend notify to target start/success events separately.

Thanks

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
christopherthielencommented, Sep 22, 2016

For anyone searching, there will not be updates on this issue because 1.0 deprecates the state events. {notify: false} no longer has any effect.

2reactions
christopherthielencommented, Jun 23, 2015

@pootzko that depends on what you’re trying to do (assuming with notify: false). In @homerjam’s example, I think managing the infinite loop using a separate variable like retryInProgress would work.

$on("$stateChangeStart", event, to, toParams) {
  if (to.retryInProgress) {
    to.retryInProgress = false;
    return;
  }
  // do  stuff
  event.preventDefault();
  to.retryInProgress = true;
  $state.go(to, toParams);
}

@leonpapazianis yes, it is on the roadmap. You can use the proof-of-concept I added to ui-router-extras for now. See #1257 for details. I think code like this should work:

$on("$stateChangeStart", event, to, toParams) {
  // UI-Router Extras decorates the injector so you can do this in a event handler... 
  // UI-Router 1.0 will only allow $transition$ injection in places where resolves are normally injected.
  var t = $injector.get("$transition$"); 
  t.promise.then(transitionSuccessFn);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Bubbling and capturing - The Modern JavaScript Tutorial
To stop the bubbling and prevent handlers on the current element from running, there's a method event. stopImmediatePropagation() .
Read more >
Script Syntax - Home Assistant
alias: "Notify about the state of the blind" service: notify.mobile_app_iphone ... When a condition does not return true , the script will stop...
Read more >
Fact check: 20 false and misleading claims Trump made in his ...
Former President Donald Trump began his 2024 presidential campaign just as he ended his presidency in 2021: with a whole lot of inaccuracy....
Read more >
Behavior changes: Apps targeting Android 12
Learn about changes in Android 12 that will affect apps when they target Android 12.
Read more >
Create, test, and tune a DLP policy - Microsoft Learn
This is an effective way to introduce DLP policies to your end users, and do user awareness training, without risking too many false...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found