I want to put a clear icon/button on my all inputs. Is it possible to use the component as an attribute which has clear button HTML as this component will be used on all inputs as an attribute selector
Basically i want to make following code as directive or component as attribute which is reusable
<button mat-button *ngIf="value" matSuffix mat-icon-button aria-label="Clear" (click)="value =''"> close
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: '[appClearInput]',
templateUrl: './clear-input.component.html',
styleUrls: ['./clear-input.component.scss'],
})
export class ClearInputComponent implements OnInit {
@Input() appClearInput: any;
@Input() inputs: any;
constructor() {
// console.log(this.inputs);
}
ngOnInit(): void {}
ngAfterViewInit() {
setTimeout(() => {
console.log(this.inputs);
});
}
clearValue() {
this.inputs.value = '';
}
}`
//ClearInputComponent HTML
<button
mat-button
matSuffix
mat-icon-button
aria-label="Clear"
(click)="clearValue()"
>
<mat-icon style="font-size: 18px;">close</mat-icon>
</button>
//Using component as attribute
<mat-form-field fxFlex [ngClass.gt-xs]="'min-ctrl'">
<input
matInput
type="text"
placeholder="Invoice No"
formControlName="invoiceNo"
#inputpurchaseInvoiceNo
maxlength="80"
[appHighlight]="'yellow'"
[appClearInput]="inputpurchaseInvoiceNo"
/>
(click)="clearValues(form.get('fieldName'))"
– Kamran Khatti