How to not apply [routerLink] on a child element?

FlashCode

I want to make a child element to trigger it own click even , and don't respond to it parent element having [routerLink], the problem is the child element can't run it delete() function in (click)="delete()" it just follow it parent in [routerLink] (it navigate to /product/:id)

    <div class="item">

<!-- parent element -->
    <a [routerLink]="['/product/'+product.id]">
        <div class="figure">
          <div class="sides">
            <div class="side">
              <div class="card">
<img class="img" [src]="product.thumb"> 
                <div class="content">
                  <div class="header">{{product.name}}</div>
                  <div class="meta"> <span>product.category</span> </div>
                </div>
                <div class="extraContent"> <span class="ui right floated black">

                <!-- child element -->
                <a (click)="delete()" ><i class="red trash outline icon"></i></a></span> <span><i class="deleteProductIcon"></i></span> </div> 
                <!-- child element -->

              </div>
            </div>
          </div>
        </div>
      </a>
<!-- parent element -->

</div>

I tried to move [routerLink] to an upper div but it still doing the same behavior

LLai

if you stopPropgation in the delete function() the event won't bubble up to the anchor tag with the routerLink

// pass in the event object to the delete function
<a (click)="delete($event)" ><i class="red trash outline icon"></i></a>

// in the delete function, stop event propagation
delete(event){
    event.stopPropagation();
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to set css child element but not apply for inside element of child element?

How to apply style to child of element with active state

How to apply CSS on child element when hover parent element?

How to apply css property to a child element using JQuery

How to apply an id attribute to a child element of a ReactJS component?

How to apply rule to child element only after It is created (CSS)?

Css problem how to apply changes when i hover a parents child element to another parents child element?

How to prevent overriding of parent routerLink over child

Apply hover effect on child element

How to apply CSS to an element which doesn't have a certain element as a child? JS solution allowed

Apply style to child that are under certain element

Apply css style to child element of parent class

XSLT Apply Templates where child element starts with 'A'

MakeStyles (Material UI) apply style to child element

Can't apply template to child element

routerLink error in child route

routerLink with singleline if and child route

RouterLink not working in child components

How to add cursor to parent element and apply that to child elements too using css?

How can I apply href and data-toggle to an element except one of its child elements?

How to access a child element of $(this)

Apply CSS rules if element isn't a child of other element

Add element with RouterLink dynamically

How can I clicked with [routerLink] inside a child view to another child view?

How to apply mouseleave in dynamic element?

How to selectively apply a script to an element?

How to access a child of a child of an element by tagname

RouterLink to navigate back in child route

Angular 2 - Apply conditional style to a directive's child HTML element