Good Morning from Germany,
first my code works like a charm and I´m happy about the awesome learning curve with Angular 2. I´m getting things faster done than any time before.
My problem is that I dont understand why the databinding works. For what I see, I dont get any piece of code which would it explain. Hope someone can give me a hint.
Basicly I got 3 variables:
employee: Employee[]; //For editing a single Employee
employees: Employees[]; //Collects all Employees (Received from PHP)
pagedItems: any[]; //Stores some of the Employees[] to page trough them in ngFor
Creation of the list:
<ng-template ngFor let-i="index" let-c="count" let-weeks [ngForOf]=" pagedItems">
<div (click)="showDialog($event, people)" *ngFor="let people of weeks; let i2 = index;">
...
pagedItems get defined by employees.slice
ShowDialog (=Formular to change a employee):
showDialog(event, people) {
this.employee = people[0];
//console.log(people[0]);
}
My Formular:
<p-dialog styleClass="boxSettings" header="Datenerfassung" [(visible)]="displayDatacollect">
<form-ShiftData *ngIf="employee" [employee]="employee">
</form-ShiftData>
</p-dialog>
In the formular I bind everything to the employee class. On submit I save the data in the database.
So this is basicly everything I do. My problem is now that I dont understand why, If I change the employee class in my formular (even in front of submitting) the class employees and the pagedItems class are changing. And so also my List.
What I see is that I set the variables like: employees -> pagedItems -> people -> employee
But no line which could lead in the other direction. So somehow Angular does this on his own.
If you could explain it or just send a tutorial which explains it, I would be very happy.
EDIT 1:
@Input('employee') employee: Employee;
This way I import it in the formular component, also not quite sure why I dont write here:
@Input('employee') employee: Employee[];
But otherwise it wont work.
Ah and If I already ask, If you have a hint how I can set displayDatacollect (Formular) inside of form-ShiftData (Separate Component) I would be happy to :D