0

Code:

<table>
 <tr ng-click="function()">
  <td id="1"></td>
  <td></td>
 <tr>
</table>

How to delete click-handler from td with id = 1? Thanks

2
  • Sorry, could you explain it better? Commented Oct 22, 2013 at 21:23
  • This question about something like "stop propagation". I want to click td with id=1 and not fire click event for parent <tr> Commented Oct 22, 2013 at 21:25

2 Answers 2

1

I'm going to take this to mean that you don't want to fire the click event handler in td id=1, but you do want every other td in that row to still fire it.

ng-click wires up regular javascript event handlers. Since you are listening for the click event on the tr element, you simply have to stop the event from propagating when it fires on a child element to ahiceve this.

It would probably be best written as a directive

app.directive('disableClick', function() {
  return function(scope, elem) {
    elem.on('click', function(e) {
      // e.stopPropagation(); or for IE, window.event.cancelBubble
      return false; // My assumption is that jqLite supports this, jQuery definitely does.
    });
  }
});

HTML

<td disable-click id="1"></td>

The click event will no longer bubble up to the TR.

Sign up to request clarification or add additional context in comments.

Comments

0

The proper way to do it, it's in a directive. I found one that it could help you Here you go an example click no bubble

angular.forEach( 'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter   mouseleave'.split(' '),
    function(name) {

        var directiveName = name.replace('my-' , '');

        app.directive( directiveName, ['$parse', function($parse) {
            return function(scope, element, attr) {
                var fn = $parse(attr[directiveName]);
                element.bind(lowercase(name), function(event) {
                event.stopPropagation();
                scope.$apply(function() {
                fn(scope, {$event:event});
            });
        });
    };
}]);

I hope it helps

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.