AngularJS有&参数,其中你可以传递一个回调到指令(例如AngularJS的回调方式。是否可以将回调函数作为@Input
传递给Angular组件(如下所示)?如果不是,那最接近AngularJS的功能是什么?
@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>