2014-02-11 58 views
0

首先,我想說我已經看到一些已經有類似問題的主題。我已經嘗試了這些主題的迴應,但是我一直無法爲我的問題找到解決方案。也許不同的是,我使用AngularJS如何在單擊AngularJS中的鏈接時觸發onclick()事件

(HTML)

<li class="article-list_item" ng-repeat="noticia in news" > 
    <article class="article_news" id="newsBlock{{noticia.id}}" >  
     <header> 
      <h1 class="article_newsTitle"> 
       <a href="http://www.google.es" rel="tooltip" title="{{noticia.title}}" 
        data-toggle="modal" ng-bind-html-unsafe="noticia.shortTitle"></a> 
      </h1> 
     </header> 
    </article> 

(JS)

$(document).ready(function() { 
    $(".article_news").click(function (event) { 
     $(this).addClass("approved"); 
    }); 
}); 

我所試圖做的是要添加的類別「已批准」到我點擊的對象。

但是,當我點擊<article>裏面的鏈接,我不想添加類。相反,我希望瀏覽器打開URL。

我該怎麼做?我必須使用stopPropagation(),preventDefault()或類似的?我應該如何使用它們?

在此先感謝

回答

0

好,角全自動過濾器鏈接行動,如果你在角的方式實現它。爲了以角度實現它,你應該創建指令來綁定處理你的問題的點擊事件。你仍然可以像這樣解決它。

ng-click="$event.stopPropagation()" 

HTML

 <article class="article_news" id="newsBlock{{noticia.id}}" >  
     <header> 
      <h1 class="article_newsTitle"> 
       <a ng-click="$event.stopPropagation()" href="http://www.google.es" rel="tooltip" title="{{noticia.title}}" 
        data-toggle="modal" ng-bind-html-unsafe="noticia.shortTitle"></a> 
      </h1> 
     </header> 
    </article> 
+0

哇的作品!謝謝。我很生氣,我無法做到這一點......再次感謝您的幫助。 – Havor

相關問題