Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-click in parent div also in child div

I've the following code:

        <table class="table">
            <tr>
                <th>Name___</th>
            </tr>
            <tr ng-repeat="app in apps"
                ng-click="go('/editApp/' + plugin.name);">

                <td>
                    <span>{{app.name}}</span>
                </td>
                <td style="width: 100px;">
                    <i class="glyphicon glyphicon-pencil" 
                              ng-click="openPopup(app)"></i>
                </td>
            </tr>
        </table>

When I click on the OpenPopup, also the go() method firing, how can I do that, If I click on popup just the popup will fire?

like image 225
Ramzy Abourafeh Avatar asked Mar 04 '14 11:03

Ramzy Abourafeh


1 Answers

This executing because your <td> nested in <tr>, and click firstly fired openPopup()

then fired go(). You can use $event.stopPropagation() for stop event propagation to <tr>. Try

        <table class="table">
        <tr>
            <th>Name___</th>
        </tr>
        <tr ng-repeat="app in apps"
            ng-click="go('/editApp/' + plugin.name);">

            <td>
                <span>{{app.name}}</span>
            </td>
            <td style="width: 100px;">
                <i class="glyphicon glyphicon-pencil" 
                          ng-click="openPopup(app);$event.stopPropagation()"></i>
            </td>
        </tr>
    </table>
like image 146
strelok2010 Avatar answered Oct 06 '22 09:10

strelok2010