2

I have 2 states; viewOrder and saveOrder. Their definition looks like this:

$stateProvider.state('viewOrder', {
    url: "/orders/:orderNumber",
    templateUrl: 'tpl/orders/view.html',
    controller: 'ViewOrderController',
    controllerAs: 'controller'
});

$stateProvider.state('saveOrder', {
    url: '/orders/save?orderNumber',
    templateUrl: 'tpl/orders/save/index.html',
    controller: 'SaveOrderController',
    controllerAs: 'controller'
});

When I use $state.go('saveOrder') it gets confused and thinks I am trying to view an order and believes the /save is the actual order number. Is there a way I can keep my URL like it is, but stop the confusion?

4
  • You want to hide parameters from url? Commented Jan 5, 2017 at 14:06
  • no, I don't want the URLs to get confused with each other Commented Jan 5, 2017 at 14:13
  • Question is little bit not clear. Please explain in detail Commented Jan 5, 2017 at 14:15
  • Change the urls to have different words. Commented Jan 5, 2017 at 14:15

2 Answers 2

2

Try this, I have added the url param in saveOrder with a colon..

$stateProvider.state('viewOrder', {
    url: "/orders/:orderNumber",
    templateUrl: 'tpl/orders/view.html',
    controller: 'ViewOrderController',
    controllerAs: 'controller'
});

$stateProvider.state('saveOrder', {
    url: '/orders/save/:orderNumber',
    templateUrl: 'tpl/orders/save/index.html',
    controller: 'SaveOrderController',
    controllerAs: 'controller'
});
Sign up to request clarification or add additional context in comments.

Comments

0

Your $state.go('saveOrder') is changing without parameter.

change like this $state.go("saveOrder", { "orderNumber": 123});

$stateProvider.state('viewOrder', {
    url: "/orders/:orderNumber",
    templateUrl: 'tpl/orders/view.html',
    controller: 'ViewOrderController',
    controllerAs: 'controller'
});

$stateProvider.state('saveOrder', {
    url: '/orders/save/:orderNumber',
    templateUrl: 'tpl/orders/save/index.html',
    controller: 'SaveOrderController',
    controllerAs: 'controller'
});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.