Answer the question
In order to leave comments, you need to log in
How to call component method in ng-content in Angular 2?
The title is not entirely clear, here is a specific example:
HomeComponent template:
<app-step-controls>
<button>Назад</button>
<button (click)="toNextStep('test')">Вперед</button>
</app-step-controls>
<div>
<ng-content></ng-content>
</div>
Answer the question
In order to leave comments, you need to log in
Add exportAs to the component:
@Component({
selector: 'app-step-controls',
template:
`
<div>
<ng-content></ng-content>
</div>
`,
exportAs: 'appStepControls'
})
export class AppStepControlsComponent {
}
<app-step-controls #ascs="appStepControls">
<button>Назад</button>
<button (click)="ascs.toNextStep('test')">Вперед</button>
</app-step-controls>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question