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

后端 未结 10 1630
庸人自扰
庸人自扰 2020-11-27 10:22

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

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 10:37

    I think that is a bad solution. If you want to pass a Function into component with @Input(), @Output() decorator is what you are looking for.

    export class SuggestionMenuComponent {
        @Output() onSuggest: EventEmitter = new EventEmitter();
    
        suggestionWasClicked(clickedEntry: SomeModel): void {
            this.onSuggest.emit([clickedEntry, this.query]);
        }
    }
    
    
    
    

提交回复
热议问题