I'm trying to create a component with a cancel and send buttons to avoid c&p on each form but I can't find a way to pass functions as a parameter to the component selector
HTML:
<btn-submit [cancelFunction]='test' [acceptFunction]='test'></btn-submit>
TS Parent:
test = () => console.log("this is a test");
TS Child:
import { Component, Input } from '@angular/core';
@Component({
selector: 'btn-submit',
styleUrls: ['./btn.component.scss'],
template: `
<button class="btn" click="cancelFunction()">
<fa name="times"></fa>
</button>
<button class="btn" click="acceptFunction()">
<fa name="check"></fa>
</button>
`
})
export class BtnSubmitComponent {
@Input() cancelFunction: any;
@Input() acceptFunction: any;
}
Outputinstead reallyInputdecorator, but need to bind it using property binding. Also, I think you want to pass in the function, not execute the function, so you may need to take the()off.