How to get the id of the button clicked on a result listing line by Angular JS?

Asked

Viewed 55 times

0

How to get the id of the button clicked on a result listing line by Angular JS?

In the HTML page I can use list.id, but in the code in Angularjs, the codes below return me Undefined:

id;

$scope.id;

$scope.listagensRelatorios.id;

$scope.parametro.id;

$routeParams.id 


    app.controller("listagemRelatoriosController", function($scope, $http, $location, $q) {

    $scope.listagensRelatorios = [];
    $scope.listagemRelatorio = {};

    carregarListagemRelatorios = function() {

        $http({
            method : 'GET',
            url : 'http://localhost:8080/listagemRelatorios',

        }).then(function(response) {
            $scope.listagensRelatorios = response.data;

        }, function(response) {
            console.log(response.data);
            console.log(response.status);
        });

    };


    gerarRelatorioSelecionado = function() {

        $http({
            method : 'GET',
            url : 'http://localhost:8080/listagemRelatorios' + $scope.listagensRelatorios.id,

        }).then(function(response) {
            $scope.listagensRelatorios = response.data;

        }, function(response) {
            console.log(response.data);
            console.log(response.status);
        });

    };



    carregarListagemRelatorios();
    gerarRelatorioSelecionado();

});

1 answer

0

You can pass the id in the function call in html.

HTML:

 <div ng-click="getId(list.id)">List item</div>

Function:

 $scope.getId = function(param) {
   console.log(param);
   //insira o código aqui
 }

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.