10
Angular将回调函数作为@Input传递给子组件,类似于AngularJS的方式
AngularJS具有&参数,您可以在其中将回调传递给指令(例如AngularJS的回调方式。是否可以将回调作为@InputAngular Component的传递(如下所示)? 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>