In my Angular program, I have a table where whenever you click on a row, it goes into a different component, row-edit.component
, and the row is turned into input boxes so that you can edit the data and passed the number of the row that's selected. I want to be able to make a copy of the array that's displayed in the table so that if someone changes something they didn't mean to, they can just hit a cancel button and it will reset the row to what it originally was. How can I make a copy of the array? - I thought what I had worked, but when it's displayed to the console, I'm just getting undefined
Here's the model of my array:
public class PTOData
{
[Key]
public int ID { get; set; }
public int EmpKey { get; set; }
public string type { get; set; }
public DateTime date { get; set; }
public string fullhalf { get; set; }
public int hours { get; set; }
public string scheduled { get; set; }
public string notes { get; set; }
public bool inPR { get; set; }
public DateTime? prDate { get; set; }
}
}
here's where the main function is called in my .html:
<button class="btn btn-default btn-primary btn-sm" (click)="resetRow(pto)"><i class="fa fa-ban" aria-hidden="true"></i></button>
and here's the relevant parts of my .ts file, the console.log(this.origPTO);
is just so I can see what's printing out and currently, I'm getting undefined
in the console
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { PTOData } from './pto-data';
import { PTODataService } from './pto-data.service';
import { EmpInfo } from './emp-info';
import { EmpInfoService } from './emp-info.service';
@Component({
selector: '[pto-row-edit]',
templateUrl: `./row-edit.component.html`,
styleUrls: ['./row-edit.component.css']
})
export class RowEditComponent {
// Inputs & Outputs to/from grid component
@Input() pto: PTOData[];
@Input() rowSelected: number;
@Output() onDelete = new EventEmitter<number>();
@Output() onSave = new EventEmitter<number>();
origPTO: PTOData[] = this.pto;
constructor(
private ptodataService: PTODataService,
private empInfoService: EmpInfoService) { }
resetRow(pto: PTOData): void {
console.log(this.origPTO);
this.rowSelected = null;
this.onSave.emit(this.rowSelected);
}
}