1

I am trying to store multiple objects in array but I was able to store only one object at a time. I want to add multiple dates selected by the user and save them in an array but whenever I add the second date it replaces the first one.
My HTML code is:

  <div class="appointmensts">
     <ion-label>Appointmensts</ion-label>

     <ion-row>
       <ion-col col-8>
          <ion-item>
              <ion-datetime placeholder="dd-mm-yyyy" displayFormat="YYYY-MM-DD"   [(ngModel)]="addServices.appointment_dates" ></ion-datetime>
            </ion-item>
       </ion-col>
       <ion-col><span><button (click)="addService()"><ion-icon><img src="../../../assets/img/addservice.png" alt=""></ion-icon>Add</button></span></ion-col>
     </ion-row>
   </div>

My .ts code is:

public addServices: {  service_name: string , price: string, duration : string ,unit : string,  appointment_dates : Array<AnalyserNode>} = {


    service_name : '',
    price : '',
    duration : '',
    unit : '',
    appointment_dates : []


  }



  addService(){



  console.log(this.addServices.appointment_dates);

  }

1 Answer 1

3

Maybe you can bind your [(ngModel)] with a new variable for example appointment_tmp;

and then in your addService()

this.addServices.appointment_dates.push(this.appointment_tmp);

working example

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.