I am trying to call an action in a state directly when I enter it. (Actually in my app I am trying to call an action on my state’s parent state, but the net result is the same.)
In my app, I transition from StateOne to StateTwo. When I enter my state, StateTwo, I call manager.send(“myStateTwoAction”). However, I immediately get an error
Uncaught Error: <Ember.StateManager:ember1424>
could not respond to event myStateTwoAction in state StateOne.
Note that this is in my StateTwo enter method.
Here is my jsFiddle: http://jsfiddle.net/SamFent/YGX2Y/
Does anyone know if there’s a way to call a state’s action from within the new state’s enter method?
You cannot call a state action in the
entermethod. As you can see here: https://github.com/emberjs/ember.js/blob/master/packages/ember-states/lib/state_manager.js#L861 the currentState is set after the enter method is called.But you can implement the
setupmethod witch is called just after a state has been entered.see: http://jsfiddle.net/YGX2Y/2/
I hope this works for you.