I have the following attribute directive
import { Directive,HostListener,Input } from '@angular/core';
@Directive({
selector: `[appConfirmaction]`
})
export class ConfirmactionDirective {
@Input() appConfirmaction = () => {};
@Input() confirmMessage = 'Do you want to keep going?';
@HostListener('click', ['$event'])
confirmFirst() {
const confirmed = window.confirm(this.confirmMessage);
if(confirmed) {
this.appConfirmaction();
}
}
}
Then I'm using the above directive attribute in a button, such as
<button md-icon-button [appConfirmaction]="showSimpleMessage" >
The code of the function of the component is:
showSimpleMessage(){
alert("Hello");
}
This code works perfectly.
Now, suppose that I want to add a parameter to the function showSimpleMessage, such as
showSimpleMessage(name:string){
alert("Hello "+name);
}
What are the changes that I have to do to the attribute directive to support the new parameter without using a new @Input for the name parameter? Also, Is this the proper way to call a function from an attribute directive with Angular4?
Cheers.