2014-02-11 4 views
3

내가 다음과 같은 HTML 코드가 NG가 클릭을 통해 NG 클릭 :AngularJS와 -

<div class="outerdiv" data-ng-click="resetText()"> 
    <div class="innerdiv" data-ng-click="showText()"> 
     {{ text }} 
    </div> 
</div> 

ng-click을 가진 외부 DIV하고 다른 ng-click와 내부 DIV.

내 문제는 : 내부 div를 클릭하면 외부도 실행 중입니다. 나는이 문제를 해결하기 위해 할 수있는 일 (

나는 그것이 하드 플래그를 사용하여 작업 할 수 있습니까? 내부 기능이 아닌 외부를 발사,하지만 난 race condition 문제의 얼굴에있어 확실하지.

을 여기. Fiddle 문제를 도시

+0

중첩 된 ng-click 호출 사이의 이벤트 전파를 취소하는 가장 좋은 방법은 무엇입니까? (http://stackoverflow.com/questions/15193539/whats-the-best-way-to-cancel- 중첩 클릭 - 호출 간 이벤트 전파) – Stewie

답변

10
<div class="innerdiv" data-ng-click="showText($event)"> 

하고 컨트롤러

$scope.showText = function(event) { 
    // whatever 
    event.stopPropagation(); 
} 
2

,174 사용해
<div class="outerdiv" data-ng-click="resetText()"> 
    <div class="innerdiv" data-ng-click="showText();$event.stopPropagation()"> 
     {{ text }} 
    </div> 
</div>