0

I have a list of elements, each containing a ng-click. Nested inside each element is a div that should toggle a Bootstrap modal.

I have added the $event.stopPropagation to the nested div because i don't want the ng-click event from the parent element to fire, but this causes the modal to not begin displayed.

    <div id="segment{{segment.Id}}" class="message" ng-class="{activeSegment: segment.Selected}" ng-click="!segmentIsLoaded || selectSegment(segment)">
        <div>
             <div class="pull-left">
                 <span>ID: {{segment.Id}}</span>
                 <span>{{segment.Name}}  </span>
                 <i class="fa fa-info-circle fa-lg" data-toggle="tooltip" data-original-title="{{segment.Description}}" tooltip></i><br />
                                        <small>{{formatJsonDate(segment.Updated)}}</small>
              </div>
              <div class="btn btn-danger pull-right" data-toggle="modal" data-target="#deleteSegmentModal" ng-click="$event.stopPropagation();">
                   <span><i class="fa fa-trash-o" aria-hidden="true"></i></span>
              </div>
         </div>
     </div>

Any known work-arounds for this?

I should perhaps mention that the stopPropagation() works as far as preventing the click event from firing. My issue is with the bootstrap modal not being activated through data-toggle attribute

1 Answers1

1

Have you tried using a directive

<a ng-click='expression' stop-event='click'>
.directive('stopEvent', function () {
    return {
        restrict: 'A',
        link: function (scope, element, attr) {
            if(attr && attr.stopEvent)
                element.bind(attr.stopEvent, function (e) {
                    e.stopPropagation();
                });
        }
    };
 });

check SO link How can I make an AngularJS directive to stopPropagation?

Community
  • 1
  • 1
Nair Athul
  • 823
  • 9
  • 21
  • Could you explain why, using a directive, would stop angular from inferring with the Bootstrap data-toggle event? – Jan Molbech May 04 '17 at 09:22