Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

269
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda