Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

276
Views
How to set up path paramater in angular and access in the controller?

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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;
        });
    }
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!