1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Angular pass callback function to child component as @Input similar to AngularJS way

Discussão em 'Angular' iniciado por Michail Michailidis, Outubro 6, 2024.

  1. AngularJS has the & parameters where you could pass a callback to a directive (e.g AngularJS way of callbacks. Is it possible to pass a callback as an @Input for an Angular Component (something like below)? If not what would be the closest thing to what AngularJS does?

    @Component({
    selector: 'suggestion-menu',
    providers: [SuggestService],
    template: `
    <div (mousedown)="suggestionWasClicked(suggestion)">
    </div>`,
    changeDetection: ChangeDetectionStrategy.Default
    })
    export class SuggestionMenuComponent {
    @Input() callback: Function;

    suggestionWasClicked(clickedEntry: SomeModel): void {
    this.callback(clickedEntry, this.query);
    }
    }


    <suggestion-menu callback="insertSuggestion">
    </suggestion-menu>

    Continue reading...

Compartilhe esta Página