0

Basic problem is, I have a modal window which I want to activate when certain terms are not satisfied. Modal should be active ( disabling user to do anything else but clicking on a modal button) on every state/URL change. I managed to have that working when manually typing correct 'state addresses', e.g. there is state.('dogs') and when I type 'dogs', modal stands open and nothing else is happening. Yet, if I mistype e.g. 'dogzz' modal closes.

The root of the problem is that I control modal with

$rootScope.$on('$stateChangeStart', function(event...

It turns that UI-Router won't detect anything that isn't registered as a state? I tried

$rootScope.$on('$stateChangeError', function (event) {...

and it won't catch 'irregular' i.e. mistyped URL. I console logged

'$stateNotFound', '$stateChangeError', '$stateChangeStart'

and nothing catches mistyped URLs. Searching for some universal, non ui-router solution didn't help, which is kinda strange because 'route prevent' problem seems to be universal.

So, I need to catch mistyped route changes, in essence.

Kalamarico
  • 5,466
  • 22
  • 53
  • 70
Gishas
  • 380
  • 6
  • 21
  • 1
    Do you have an `otherwise` fallback defined? i.e. `$urlRouterProvider.otherwise('/something')` Not 100% sure, but that might prevent `$stateNotFound` from firing. – mikwat Apr 24 '18 at 17:24
  • I have `$urlRouterProvider.otherwise('/')` and I already tried to comment it out, but to no avail. It seems that problem is somewhere else. Managed to solve it other way, yet I'm still keen to know why 'StateNotFound' didn't fire. Thanks for the comment. – Gishas Apr 25 '18 at 09:16
  • @mikwat Well, what I did next is to console.log very angular-ui-router 'othervise' function, to see when it's called. Funny enough, it's called on page load/reload for some reason, but it won't get called when I (mis)type URLs manually. So I guess it's not 'otherwise' that blocks this, after all. – Gishas Apr 25 '18 at 13:38
  • Huh, that's really strange. What version of angular and angular-ui-router are you using? – mikwat Apr 25 '18 at 16:18
  • Angular: 1.3.15, angular-ui-router: 0.2.13 – Gishas Apr 26 '18 at 09:24
  • Maybe related to https://stackoverflow.com/questions/27120308/angular-ui-router-urlrouterprovider-when-not-working-when-i-click-a-ui-sref – mikwat Apr 26 '18 at 15:46
  • Thanks, I'll check it out! – Gishas Apr 26 '18 at 16:50

0 Answers0