-
Notifications
You must be signed in to change notification settings - Fork 3k
Error Cannot read property 'globals' of null #326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Have you checked the thingamajig? |
Just kidding, the problem is we need more context, your issue is immensely too vague. Can you create a plunkr that shows the error? |
I've started experiencing this issue. I've traced it down to this line Preview:
I'm not certain how the This happened when I clicked on a |
Here's some additional context... My (relevant) routes look like this:
Then I click: Would love a tip on how to accomplish what I'm trying to do in a better way :) (that being, show a login page |
@timkindberg any thoughts on this? I'm still seeing it and I'm not sure why... |
root.route only has a url and onEnter, so maybe that has something to do with it. |
I decided to ditch root.route altogether. So I'm not seeing this problem anymore... Still not sure what caused it though. |
You're welcome to post a Plunkr that reproduces the issue. |
@nateabele, I was able to reproduce this, albeit in a different fashion, with Angular v1.2.22 and ui-router v0.2.10. One) Create a state with an .state('left.link1', {
url: 'link1',
onExit: function() {
console.log('I will explode your router');
}
}) Two) Create another state that redirects to a third state in the .state('right', {
url: "/right",
onEnter: ['$state', function($state) {
$state.transitionTo('left');
}]
}); This error message will be thrown. The use-case for this is: I have some data that I want to share between a parent state and its child states, which a service helps with. On exit I tear down that shared service. This works fine in the majority of apps. However, my logout state is unique. It does some logging out things, then redirects you to the login. All of this happens in Am I doing something unusual here? Should I not be redirecting in To see this in action, check out this Plunkr. Click "Link1" in the Left tab, then go to the Right tab. Just a note: I didn't make the original Plunkr. I just googled 'ui-router plunkr' and modified the first one that came up. 💥 |
I suspect any time you transition from a state that has an onExit to a state that has an onEnter, this bug shows up. |
@dougalcorn, I modified the Plunkr to test your theory, and it doesn't seem to throw the error. |
OK, here's the problem. I have a state ( It seems like I would have expected the second transition's |
Sounds to me like you've nailed it, @dougalcorn. Do you think you would you have time to look into patching up this section of the code to introduce a PR? |
I'm not sure what the right fix is. Can I just add an existential check for |
Hmmm, yeah, it's a tough one given my tenuous understanding of the router's internals. That solution seems like it would work, but it doesn't seem that elegant. It'd be more robust if there were some way to take a different action if this situation is detected. Like "oh, okay, I'm being forwarded along and will never enter the state, so something else entirely needs to happen now instead of the code that explodes." But as to the specifics of how to implement this I admit that I'm unsure! |
@dougalcorn and @jmeas I was having this issue and used @dougalcorn proposed fix above and it fixed the issue for me. Is this something that can be put into the code? I don't mind helping however. I've never been involved in open source so please excuse my ignorance to the process. |
I looked at the code a little closer and it looks like it's processing a potential set of OnExit actions. I'm assuming it's doing this to support nested states. That makes @jmeas comment above seem like the correct approach. The behavior of what to do when a transition from an OnExit contains a transition would need to be defined. Things like what if there is more than one OnExit with a transition would need to be considered. What's the way forward on this? I'd like to help however. |
Yes, my fix proposed above doesn't really fix the problem. If there is a state transition during either On Mon, Aug 25, 2014 at 7:41 AM, RyanVice [email protected]
|
For others dealing with this issue, I ended up using $location.path('\blah'); in my code and it worked. I also tested and verified that using this approach still aloud the target route to have an onEnter() fire. |
Another solution for anyone facing this issue: as silly as it seems, try adding a $timeout around your transition from onEnter, if possible. The bug seems to occur due to processing a new transition during onEnter, so the $timeout will allow the original transition to complete before starting a new one, fixing the problem for me. |
Faced this issue, when a link that I click have |
I found this error using an OnEnter on a abstract state, no onExit or onEnter on the state I want to transition to |
I was also getting this issue in a redirect in an onEnter, and wrapping the $state.go in a $timeout seems to have done the trick, but it causes the initial state to flicker in before the state change. $location.path only seems to work with the $timeout as well resulting in the same issue. Anyone have an idea of how I might get the redirect without the flicker? |
I've also solved it with a timeout |
@codephobia The reason you're getting the flicker is because 'onEnter' and 'onExit' callbacks get called when a state becomes active and inactive respectively. When you use onEnter and in combination with the timeout ui-router it loads the current route then when your timeout completes your redirected with $state.go (or however your redirecting within the timeout). Instead try to do your redirect logic inside a 'resolve' (not onEnter). A resolve function will be run prior to the current route's controller and view loading, so if you do a $state.go from within a resolve function your flicker should go away. |
I face this issue while back from the browser window, and it's working fine from the app. |
It happen sometime but I don't know why.
Do I need to check something?
The text was updated successfully, but these errors were encountered: