środa, 1 lutego 2017

How to pass two parameters in AngularJS ui-sref directive


I have button, where I pass two parameters - id and lastOrderedPosition:

          <button type="submit"
                                    ui-sref="bar-order-opened.add-product({id:orderOpened.id, lastOrderedPosition:orderOpened.productsToOrder.length})"
                                    class="btn btn-primary">
                                <span class="glyphicon glyphicon-plus"></span>
                                <span class="hidden-xs hidden-sm" data-translate="entity.action.add-product">Add</span>
                </button>


Now I need a proper state. Parameters are passed in url:

        .state('bar-order-opened.add-product', {
            parent: 'bar-order-opened',
            url: '/{id}/{lastOrderedPosition}/addprod',
            data: {
                authorities: ['ROLE_BARMAN']
            },
[...]

Id was generated by JHipster to get entity.
lastOrderedPosition it’s additional parameter I need.           
To get it in controller it’s only needed:

vm.lastOrderedPosition = $stateParams.lastOrderedPosition; 



Brak komentarzy:

Prześlij komentarz