ng-repeat and ng-click in the same tag

716 views Asked by At

I have just looked for the same problem but I didn't find a solution. I tried some solutions and examples but nothing worked.

I have this HTML code in AngularJS:

<h2 class="text-center text-thin">{{pageTitle}}</h2>

        <input type="text" ng-model="searchText" placeholder="Search" class="center-block" />
        <div>
            <br>
        </div>
        <div class="list col-xs-12">

            <table class="tbl-catalogo">
                <tr class="even">
                    <td>Article</td>
                    <td>Family</td>
                    <td>Ice Type</td>
                    <td>Cooler</td>
                </tr>

                <tr ng-class-odd="'odd'" ng-class-even="'even'" ng-repeat="prod in list | filter:searchText" ng-click="_dettaglio3(prod);">
                    <td>{{prod.id_a}}</td>
                    <td>{{prod.id_f}}</td>
                    <td>{{prod.forma}}</td>
                    <td>{{prod.tipo_raff}}</td>
                </tr>
            </table>
        </div>

And in my controller I have this function:

$scope._dettaglio3 = function (val) {
            alert(JSON.stringify(val));
            console.log("\n\n\n\n\n\n" + JSON.stringify(val) + "\n\n\n\n\n\n");
        };

Problem: When I click in the tr the first time it's correct, when I click a second time the element passed is the first, if I click another time the element passed is correct. How i can fix this problem?

0

There are 0 answers