Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
HTML/JS: How to make an input date change another input date?

So I'm working on an Angular app and I have these two date input fields:

<div  class="col-lg-3">
      <div> {{ dataInizioLabel }} </div>
      <input required type="datetime-local" name="dataInizio" id="dateInput"
        [ngModel]="serverEvent.dataInizio | date:'yyyy-MM-ddTHH:mm'"
        (ngModelChange)="manageDateChange($event, dataInizio)" #dataInizio="ngModel">
      <small class="text-danger" *ngIf="dataInizio.errors">Campo obbligatorio</small>
    </div>
    <div class="col-lg-3">
      <div> {{ dataFineLabel }} </div>
      <input required type="datetime-local" name="dataFine" [ngModel]="serverEvent.dataFine | date:'yyyy-MM-ddTHH:mm'" id="dataFine"
        (ngModelChange)="manageDateChange($event, dataFine)" #dataFine="ngModel">
      <small class="text-danger" *ngIf="dataFine.errors">Campo obbligatorio</small>
    </div>

manageDateChange() JS (incomplete):

 manageDateChange(date, inputField) {
if (date) {
  this.serverEvent[inputField.name] = new Date(date);
}
let inizio = new Date(date.val())
console.log(inizio)

}

I can't find a way to make so the dataInizioLabel uptades the dataFineLabel field with his same date when it gets changed. For example, if dataInizioLaber gets set to 24/04/2022, I'd need dataFineLabel to self update to the same date.

Also, console says date.val() can't work and gives an error, so I don't think that's the right way to get the date value from the input field.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You might want to try to use a two-way binding on your ngModel like this:

[(ngModel)]="serverEvent.dataInizio | date:'yyyy-MM-ddTHH:mm'"
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!