How to iterate over array of objects and update time if <mat-checkbox> is checked in angular 9?

198 views Asked by At

I have an array of objects that are within my <mat-table> the sync property is a <mat-checkbox>. I am trying to make it so that when a box is checked and then I press the "sync" button, it will update the lastSynced property with the current date and time within the table.

    export interface ConnectionData {
  name: string;
  active: boolean;
  connections: string;
  location: string;
  users: string;
  sync: boolean;
  lastSynced: Date | null;

} 

const CONNECTIONS: ConnectionData[] = [
  {name: '', active: false, connections: '', location: '', users: '', sync: false, lastSynced: },
  {name: '', active: false, connections: '', location: '', users: '', sync: false, lastSynced: },{name: '', active: false, connections: '', location: '', users: '', sync: false, lastSynced: },

];
1

There are 1 answers

2
iamaword On

Have the method that's called on the sync buttons (click) that updates the table data. Something like:

for( const connection of connectionData ) {
    if(connection.sync) {
       connection.lastSynced = new Date(); // update to current date
    }
}