doorman
doorman

Reputation: 16949

Getting clicked innerhtml href

I have a div with innerhtml containing multiple link tags. When clicking on any of the a link tags I want to trigger a function in angular2. Can angular2 take over the click event of the href tags and get the clicked word or innerhtml tag which was clicked?

Upvotes: 0

Views: 856

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657376

You can add a host listener to your component and then figure out the rest from the passed event:

@HostListener('click', ['$event'])
onClick(event) {
  if(event.target ...) {

  }
}

Upvotes: 3

Related Questions