Is there a way to check for @Output wire up from within a component in Angular?

Discussão em 'Angular' iniciado por Justin Schwartzenberger, Janeiro 10, 2025.

  1. In the ngOnInit method of a component the @Input values will have been bound so you can check those properties on the component, but there doesn't seem to be a way to check @Output event bindings. I want to be able to know if the @Output was wired up on the component or not.

    (using Angular and TypeScript)

    import {Component, Output, EventEmitter} from '@angular/core';

    @Component({
    selector: 'sample',
    template: `<p>a sample</p>`
    })
    export class SampleComponent {
    @Output() cancel = new EventEmitter();

    ngOnInit() {
    // would like to check and see if cancel was used
    // on the element <sample (cancel)="doSomething()"></sample>
    // or not <sample></sample>
    }
    }

    Continue reading...

Compartilhe esta Página