2016-08-11 1 views
2

모바일 각도 UI를 사용하여 사이드 바를 열고 닫습니다. 이 사이드 바에서 사용자는 사람을 검색하여 배열에서 추가하거나 제거 할 수 있습니다.배열의 요소를 삭제할 때 사이드 바가 닫힙니다.

<li ng-repeat="recipient in persons.recipients"> 
    <span class="wrapper"> 
     <span class="imageWrap"> 
      <span class="initials"> 
       {{recipient.firstName.charAt(0)}}{{recipient.lastName.charAt(0)}} </span> 
     </span> 
     <a href="" class="trash" ng-click="removeRecipient($index);"><i class="fa fa-trash-o" aria-hidden="true"></i></a> 
     <span class="details"> 
      <span class="info"> 
       {{recipient.firstName}} {{recipient.lastName}} 
       <span class="persnr">{{recipient.employeeID}}</span> 
      </span> 
     </span> 
    </span> 
</li> 

위의 HTML 코드가 사이드에있는 지침에서이다 :

은 내가 <a ...></> 클릭 때 사이드 바을 닫 사람의 배열을 보여줍니다이 반복 있습니다.

$scope.removeRecipient = function(index) { 
    $scope.persons.recipients.splice(index,1); 
} 

기능 작동을하지만 사이드를 종료하고이 작업을 수행 이유를 알아낼 수 없습니다 : removeRecipient($index); 기능은 다음과 같습니다. 따라서 사용자가받는 사람을 제거 할 때마다 사이드 바를 다시 열어야합니다. 이 사이드 바를 어떻게 열어 두어야합니까?

참고 :

솔루션

내가 바로 removeRecipient($index); 기능 뒤에 ng-click에서 $event.stopPropagation();을 추가하여 내 문제를 해결했다.

+1

사이드 바 'a'태그에 'ui-toggle'을 사용하고 있습니까? –

+0

사이드 바 'a' 태그에서'ui-toggle '을 사용하지 않습니다. –

답변

1

doc에서 한 행이 있습니다.

당신은 그 안에서 링크를 클릭 한 후 그것을 가까이하기 위해 사이드 바 내에서 UI를 턴 오프 = 'uiSidebarLeft'또는 UI 턴 - 오프 = 'uiSidebarLeft' 를 넣을 수 있습니다.

그래서 이것을 사용하거나 다음과 같이 사용할 수 있습니다. 그것에 대해

e.stopPropagation() 

은 당신이 그렇게 코드에서

<a href="" class="trash" ng-click="removeRecipient($index,$event);"><i class="fa fa-trash-o" aria-hidden="true"></i></a> 

에 $ 이벤트를 전달해야합니다, 당신은 쓸 수 있습니다.

$scope.removeRecipient = function(index,e) { 
    if(e){ 
     e.stopPropagation() 
    } 
    $scope.persons.recipients.splice(index,1); 
} 

나는 동일한 도구를 사용하지 않았지만 이것이 문제 일 수 있습니다.

+0

답장을 보내 주셔서 감사합니다. 이전에 이러한 솔루션을 사용해 보았습니다. –

+0

그래,'$ event'를 멈추고 검색을 한 결과이 줄을 발견했습니다 :'$ event.stopPropagation();'. 그것은 내 문제를 해결했다. 나는 당신의 대답을 정확하다고 생각합니다. –

+0

예. 죄송합니다. stopPropagation을 잊어 버렸습니다. 나는 대답을 업데이트 할 것이다. – Nitish

관련 문제