Search code examples
javascriptangularjsngtable

Buttons per Row in AngularJS ngTable


I need your help...

I start angularJS and I have a little problem unsolved..

<table>
    <tbody>
        <tr ng-repeat="user in users">
            <td>{{user.name}}</td>
            <td>
                <button ng-click="accept($index)"><strong>accept</strong></button>
                <button ng-click="refuse()"><strong>refuse</strong></button>    
                <p ng-show="showResult($index)"><strong>je suis ton amis</strong></p> 
                <p ng-show="showResult2()"><strong>you refuse me</strong></p>      
            </td>
        </tr>
    </tbody>
</table>

I have a table that contains 2 buttons in each line: ACCEPT and REFUSE with their respective methods accept() and refuse(). I want it to show one sentence on click...

I tried something in Fiddle : http://jsfiddle.net/TBGDu/17/

But the sentence appears many times, but I want it to appear just once where I click. I tried something with tab but for the moment nothing work!

Sorry for my bad spoken language.


Solution

  • You're inside a loop so you need to use a single variable for each item :

    $scope.accept = function(idx){
       $scope.showacceptation[idx] = true;
    }
    

    http://jsfiddle.net/TBGDu/24/