I am facing a dilemma with my child component, which dynamically generates input fields within a parent component.
<app-xxx *ngFor="let el of fieldsElements"
[ngModel]="fieldsElements[el.name]"
...
...
(keydown)="myFunction(yyy, zzz)">
</app-xxx>
The challenge I am encountering is that I need to trigger myFunction()
using the click()
event handler when a specific input field is clicked. However, for the remaining fields, I want to maintain the keydown()
event. For instance, for one of the dynamically generated input fields, I wish to use click()
instead of keydown()
. Here's an example:
<app-xxx *ngFor="let el of fieldsElements"
[ngModel]="fieldsElements[el.name]"
...
...
(click)="myFunction(yyy, zzz)">
</app-xxx>
Is there a way to achieve this in a dynamic manner within the HTML/View? I have experimented with various approaches, such as using *ngIf
and implementing if-statements within the typescript file, along with addEventListener()
, but none have proven effective.
Any suggestions or insights would be greatly appreciated.