Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add parameters to $state.go?

I have an Edit Form, where users can Update a single "auction". How can I use $state.go('auctions') correctly within the update function, so that the user gets directed to the auction-view after the update was successfull?

Or better: how can I pass parameters to this $state.go('auctions')

  // Update auction
  $scope.updateAuction = function(auction){
    auctions.updateAuction(auction, {
      product: $scope.product,
      condition: $scope.condition
    }).success(function() {
      $state.go('auctions');       // I think I need to add auction parameters here 
      ToastService.show('Auction updated');
    });
  };

The auctions $state function looks like this:

  // state for showing single Auction
  .state('auctions', {
    url: '/auctions/{product}/{id}',
    templateUrl: 'auctions/auction-view.html',
    controller: 'AuctionViewCtrl',
    resolve: {
      auction: ['$stateParams', 'auctions', function($stateParams, auctions) {
        return auctions.get($stateParams.id);
      }]
    }
  })

The Edit Form can only be accesed through the related Auction View, so maybe there is a better option to use $state.go without sending a new GET request, because the auction is already loaded?

like image 903
Alessandro Santamaria Avatar asked Oct 28 '15 13:10

Alessandro Santamaria


1 Answers

$state.go("auctions", {"product": auction.product, "id": auction.id}); 

Here is also a link with documentation:

https://github.com/angular-ui/ui-router/wiki/Quick-Reference#stategoto--toparams--options

like image 130
rave Avatar answered Sep 29 '22 05:09

rave