0

I am trying to set up route like below :

$stateProvider.state('transactions', {
                url: '/transactions',
                templateUrl: url,
                menu: 'Transactions'
            });

$stateProvider.state('audit', {
                url: '/transactions/:id/audit',
                templateUrl: 'url',
            });
        

I want user to navigate to audit page using below url:

/transactions/100/audit
/transactions/200/audit

I have a button which has some logic to redirect user to "audit" page but I am confused with how do I set up $state to achieve this?

$scope.redirectToAudit = function () {
                    $state.go('audit', {
                        id: $scope.transactionId
                    });
                }

So when this button is clicked I want to redirect user to this route "/transactions/100/audit" and get transactionId 100 in the controller of audit log page.

var app = angular.module('myApp', []);
app.controller('auditCtrl', function($scope) {
    $scope.transactionId = //retrive transactionId from the path parameter
});

I want to force transaction id in audit URL /transactions/100/auditbecause entire audit page will be working on transaction id only.

How do I set up my $stateProvider to support the URL and functionality I have described above?

1 Answer 1

1

Please let me know if this works for you.

$stateProvider.state('transactions', {
    url: '/transactions',
    templateUrl: url,
    menu: 'Transactions'
});

$stateProvider.state('audit', {
    url: '/transactions/{id}/audit',
    templateUrl: 'url',
});

----------------------

var app = angular.module('myApp', []);
app.controller('auditCtrl', function($scope, $stateParams) {
    $scope.transactionId = $stateParams.id;
});
    
----------------------

app.controller('transactionsCtrl', function($scope, $state) {
    $scope.redirectToAudit = function () {
        $state.go('audit', {
            id: $scope.transactionId;
        });
    }
});
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the answer but the thing is Transactions page is set to work with this URL : '/transactions'. Cant change that URL
Roger that. I updated my answer to work with the Transactions page. Please let me know if that doesn't do it. Happy to help you get this working if I can.
This is redirecting me to list of transaction page and not on this URL : /transactions/100/audit
I updated the code above, which is working in my local environment. Please let me know if this still isn't working in your environment. If it's not working, I'd be happy to screen share, Zoom, etc. this week to take a look your environment and help debug.
Working fine now. Thank you so much. Appreciate your help :)

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.