Привет, я использую 3 поля ввода внутри одного элемента <div>. Я хочу 3 значения полей ввода при одном вызове функции.
<div class="col-md-6" (change)="calculateDob()"> <input type="number" id='years' placeholder="Years" [(ngModel)]="ageYears" formControlName="years"> <input type="number" id='months' placeholder="Months" [(ngModel)]="ageMonths" formControlName="months"> <input type="number" id='days' placeholder="Days" [(ngModel)]="ageDays" formControlName="days"> </div> <div class="col-md-6"> <input type="date" formControlName="dateOfBirth" [(ngModel)]="setDateOfBirth" disabled> </div>
Что я уже пробовал:
<div class="col-md-6" (change)="calculateDob($event.target.id,$event.target.value)"> <input type="number" id='years' placeholder="Years" [(ngModel)]="ageYears" formControlName="years"> <input type="number" id='months' placeholder="Months" [(ngModel)]="ageMonths" formControlName="months"> <input type="number" id='days' placeholder="Days" [(ngModel)]="ageDays" formControlName="days"> </div> <div class="col-md-6"> <input type="date" formControlName="dateOfBirth" [(ngModel)]="setDateOfBirth" disabled> </div> calculateDob(total,val){ if(total==='years'){ this.ageYears = val; }else if(total==='months'){ this.ageMonths = val; }else{ this.ageDays = val; } this.birthDay = moment().subtract(this.ageYears, 'years').subtract(this.ageMonths, 'months').subtract(this.ageDays , 'days'); this.createPatientForm.controls.dateOfBirth.setValue(moment(this.birthDay).tz(this.orgTimeZone).format("YYYY-MM-DD")); if(!this.ageYears && !this.ageMonths && !this.ageDays){ this.setDateOfBirth = null; } }
Member 13782684
Я передаю два параметра id и value внутри calculateDob($event.target.id,$event.target.value) функция.