2014-03-04 131 views
11

我有下面的代碼:父DIV也是孩子DIV NG單擊

 <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> 

當我點擊OpenPopup,也是go()方法燒製,我怎麼能做到這一點,如果我點擊彈出窗口彈出只會觸發?

+2

從'tr' – Lekhnath

+0

能很好地去除'NG-click',如果你點擊你實際上點擊過其父過一個子元素。這被稱爲**事件傳播**,尤其是**事件冒泡** –

回答

32

此執行,因爲嵌套在<tr><td>,並單擊首先解僱openPopup()

然後燒製go()。您可以使用$event.stopPropagation()將停止事件傳播至<tr>。 嘗試

 <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> 
+0

優秀!工作得很好。 –