I would like to "autofill" an input depending on other form values. "id" should be "name" + "." + "combo":
<input matInput name="id" required placeholder="ID" #idValue readonly/>
<input matInput ngModel name="name" required placeholder="NAME" autoFillId />
<mat-form-field>
<mat-select ngModel name="combo" required placeholder="COMBO" autoFillId >
<mat-option value=1>Value 1</mat-option>
<mat-option value=2>Value 2</mat-option>
</mat-select>
</mat-form-field>
And this is my directive:
@Directive({
selector: '[autoFillId]'
})
export class AutoFillDirective {
@Output() idValue: EventEmitter<string> = new EventEmitter();
value: string = ".";
@HostListener('input', ['$event']) onInputChange($event) {
this.value = this.value.split(".")[0] + "." + $event.target.value;
this.idValue.emit(this.value);
}
@HostListener('change', ['$event']) onChange($event) {
this.value = $event.value + "." + this.value.split(".")[1];
this.idValue.emit(this.value);
}
}
It works separatelly, I mean, if I got "undefinded.2" if changes the combo or "myName.undefined" if changes the input.
How can I do it together?
idValueoutput?#idValueconnected with@Output?