AngularJS - multiple ng-click - event bubbling

后端 未结 2 1624
陌清茗
陌清茗 2021-02-05 00:40

In the following example:

  
  • {{item.title}}

  • 2条回答
    •  遥遥无期
      2021-02-05 01:25

      This solution worked for me (I'm only supporting recent browsers, so I tried to modify the code to be more retro-compatible):

      HTML:

    • {{item.title}}

    • Scripts:

      function remove(item, $event) {
          // do some code here
      
          // Prevent bubbling to showItem.
          // On recent browsers, only $event.stopPropagation() is needed
          if ($event.stopPropagation) $event.stopPropagation();
          if ($event.preventDefault) $event.preventDefault();
          $event.cancelBubble = true;
          $event.returnValue = false;
      }
      function showItem(item) {
          // code here
      }
      

      EDIT - Added a JSFiddle demo to try it out http://jsfiddle.net/24e7mapp/1/

    提交回复
    热议问题