Tengo una forma formal con un envoltorio de complemento de icono. quiero obtener el valor de los campos cuando el usuario hizo clic en el ícono de ese campo.
Mire en el envoltorio Addon, hay un icono y la función onClick call showFile y quiere saber en qué campo del icono del formulario se hizo clic con ese valor de campo.
fields: FormlyFieldConfig[] = [ { key: 'input', type: 'input', templateOptions: { label: 'name', addonRight: { icon:'remove_red_eye', }, }, }, }Forma
<form [formGroup]="form"> <formly-form [model]="model" [fields]="fields" [form]="form"></formly-form> </form>envoltorio adicional
import { Component, TemplateRef, ViewChild, AfterViewInit } from '@angular/core'; import { FieldWrapper } from '@ngx-formly/core'; @Component({ selector: 'formly-wrapper-addons', template: ` <ng-container #fieldComponent></ng-container> <ng-template #matSuffix> <span *ngIf="to.addonRight" [ngStyle]="{cursor: to.addonRight.onClick ? 'pointer' : 'inherit'}" (click)="addonRightClick($event)" > <mat-icon *ngIf="to.addonRight.icon" type="button" (click)="showFile($event)">{{ to.addonRight.icon }}</mat-icon> <span *ngIf="to.addonRight.text">{{ to.addonRight.text }}</span> </span> </ng-template> `, }) export class FormlyWrapperAddons extends FieldWrapper implements AfterViewInit { @ViewChild('matSuffix') matSuffix: TemplateRef<any>; ngAfterViewInit() { if (this.matSuffix) { Promise.resolve().then(() => this.to.suffix = this.matSuffix); } } addonRightClick($event: any) { if (this.to.addonRight.onClick) { this.to.addonRight.onClick(this.to, this, $event); } } showFile($event:any){ //here i got mouse event //want to know which field of form icon clicked with input value console.log($event) } }