11

Is my $stateProvider:

$stateProvider
.state('home', {
    url : '/',
    templateUrl : '/admindesktop/templates/main/',
    controller : 'AdminDesktopMainController'
}).state('company', {
    url : '/company',
    templateUrl : '/admindesktop/templates/grid/',
    controller : 'CompanyGridController'
}).state('company.detail', {
    url : '/{id:\d+}', //id is 
    templateUrl : '/admindesktop/templates/company/detail/',
    controller : 'CompanyDetailController'
});

It's work for 'company' state (I use ui-sref), but this code not work (called from 'company' state):

$state.go('.detail', {
    id: $scope.selectedItem.id //selectedItem and id is defined
});

I read official docs and answers from StackOverflow, but I don't found solution. I can't use ui-sref, I use ui-grid, and new state opened after select one row from table for editing.

What i do wrong?

3 Answers 3

25

What would always work is the full state definition:

// instead of this
// $state.go('.detail', {
// use this
$state.go('company.detail', {
    id: $scope.selectedItem.id //selectedItem and id is defined
});

In doc there are defined these options, but they depend on CURRENT state:

to string
Absolute state name or relative state path. Some examples:

  • $state.go('contact.detail') - will go to the contact.detail state
  • $state.go('^') - will go to a parent state
  • $state.go('^.sibling') - will go to a sibling state
  • $state.go('.child.grandchild') - will go to grandchild state
Sign up to request clarification or add additional context in comments.

2 Comments

I tryed, it not working for me. Maybe, regular expression is wrong?
What you should use for having id int is this - url: "/{id:int}",. Here is working plunker for you: plnkr.co/edit/0EFN6S4LolaeuLHLFmxh?p=preview
2

My error is in regular expression, really:

.state('company.detail', {
    url : '/{id:\d*}',
    templateUrl : '/admindesktop/templates/company/detail/',
    controller : 'CompanyDetailController'
 })

{id:\d*} worked (integer id).

Comments

2

To load the current state. Check this out.

$state.go($state.current, {}, {reload: true}); //second parameter is for $stateParams

Reference

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.