I have some description text from an API that I am inserting as HTML into the DOM.
<div class="activity-description" [innerHTML]="description"></div>
The description is set within ngOninit();
if (this.eventDetail.description.length > 255) {
this.description = this.eventDetail.description.substring(0, 255) + '<span class="more-description"> ...Learn More</span>';
}
I am trying to add an event listener to the "more-description" class within the ngAfterViewInit()
var el = this.elementRef.nativeElement.querySelector('.more-description');
if (el)
el.addEventListener('click', this.displayFullDescription());
The element is null and does not allow the event listener to be attached. How do I add this event listener to html elements that are dynamically added?