I have the following html ( a template in my angular 5 component ):
<div class="center">
<object id="img" data="assets/img/big_layout.svg" #svg></object>
</div>
In my component I have this:
@ViewChild('svg') svg: ElementRef;
ngAfterViewInit() {
this.svg.nativeElement.addEventListener('load', () => { // wait for the svg to load
console.log('Clicked...')
}, false);
}
As expected, this logic works correctly - when the component loads, I get Clicked...
logged for every instance of the component in the view.
However, as soon as I change the event from 'load'
to 'click'
, clicking on the svg doesn't fire any event?
Any idea why?
Update:
As noted in the linked question, the following html doesn't trigger the click event either:
<div class="center" (click)="onClick()">
<object id="img" (click)="onClick()" data="assets/img/big_layout.svg" #svg></object>
</div>
Here is a plunk demo