I am creating a reusable component which is showing a rounded image thumbnail as content. I want to detect within this component if a developer has assigned a click listener to it and modify the style and behaviour of it slightly. Basically add a cursor: pointer style if a developer assigned a (click)=anyClickCallbackFunction() on the component.
The question is, how can i read this from within the component?
for doing that you need to have click output in your component although you are not using it, then check how many observers exists
export class MycompComponent implements OnInit {
@Output() click : EventEmitter<any> = new EventEmitter<any>();
hasHandler : boolean;
ngOnInit() {
this.hasHandler = this.click.observers.length > 0;
}
}
see working example here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With