Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Jonas Sabim
Courses Plus Student 30 Points$state.go not redirecting
im trying to redirect to a specific page with a given id, but is not working, it says that cannot resolve the state.
My url example:
http://localhost/#/app/lab/edit/table/101
My js:
$state.go('app.lab.edit.table',$stateParams.calculationId); $stateParams.calculationId is my id numer (101).
Error Message:
Error: Could not resolve 'app.lab.edit.table' from state 'app.lab.result.existing' StateParams Object:
Object {calculationId: "101", calculation: null, fromSave: false} What im doing wrong?
1 Answer

Erik Nemesis
13,356 PointsProbably that you are trying to call $state.go
on an internal ui-view
that is not relative to the state you call state.go in. Let me explain:
From what I see you are in state app.lab.result.existing
, which means that your html is something of the sort (handled by $stateProvider.states)
<!-- ui view for "app" -->
<ui-view>
...
<!-- ui view for lab -->
<ui-view>
...
<!-- ui view for result, controller: ResultController -->
<ui-view>
...
<!-- ui view for existing, controller: ExistingController -->
<ui-view>
This is the content for existing
</ui-view>
</ui-view>
</ui-view>
</ui-view>
However I dont know your code but, if you try to go to app.lab.edit.table
from your ExistingController, basically ui router will try to resolve each of the parent states, that is "app", "lab", "edit" and "table". However, from your current point of view the <ui-view>
for edit
is unavailable, because it is instead the ui-view for result
. So ui router cannot switch states.
Let's do an analogy with Object inheritance:
Let's day we have those two inheritance chains
Human -> Worker -> CompanyWorker -> Employee
and
Human -> Worker -> AssociationWorker -> Volunteer
Obviously Employee and Volunteer are subclasses of Worker, but you cannot cast Volunteer
to Employee
and vice-versa.
This is what happens here.
Hope that helps
Steven Parker
215,958 PointsSteven Parker
215,958 Points