I have the following list of educations:
<cdk-virtual-scroll-viewport itemSize="5" class="list-scroll">
<app-education-item *ngFor="let education of loadedEducations"
(isSelected)="changeSelected(education)"
[ngClass]="{ selected: education == loadedEducation }"
[education]="education"
(isRemoved)="removeEducation(education)"
></app-education-item>
</cdk-virtual-scroll-viewport>
and is the following component
<div [ngClass]="{ 'list-item-container-collapsed' : isCollapsed, 'list-item-container': !isCollapsed, 'unselected': !isActive, 'selected': isActive}" (click)="selectEducation()">
<div class="top-items-container" style="display: flex;">
<div class="item-text">
<span class="txt-header">{{educationHeader}}</span>
<p class="txt-date">
<span>{{startDate}}</span> -
<span>{{endDate}}</span>
</p>
</div>
</div>
the has the following logic used to show the data taken from the parameter:
export class EducationItemComponent implements OnInit {
@Input()
education: Education;
isCollapsed = false;
isActive = false;
startDate: string;
endDate: string;
educationHeader: string;
educationDescription: string;
constructor() { }
ngOnInit(): void {
console.log(this.education);
this.startDate = this.education.startDate != '' ? formatDate(this.education.startDate, 'MMM yyyy', 'en-US')
: formatDate(new Date(), 'MM YYYY', 'en-US') ;
this.endDate = this.education.endDate != 'present' ? this.endDate = formatDate(this.education.endDate, 'MMM yyyy', 'en-US')
: this.education.endDate;
this.educationHeader = this.education.degree == undefined || this.education.description == undefined ? ''
: this.education.degree + ' at ' + this.education.school;
if (!this.education.description.enUS && this.education.description.nlNL) {
this.educationDescription = this.education.description.nlNL;
} else if (this.education.description.enUS) {
this.educationDescription = this.education.description.enUS;
}
}
I use a custom event to handle update
@Output() updatedValue: EventEmitter<any> = new EventEmitter<string>();
constructor() {}
ngOnInit(): void {}
fieldChanged(changes: SimpleChanges) {
this.updatedValue.emit(changes);
}
Then I have the following html that I use to manipulate the data:
<div class="update-wrap">
<div class="list-header">Update education</div>
<div>
<div class="col-sm-6 input-wrapper">
<app-input-field
label="Institution"
[value]="loadedEducation.school"
(updatedValue)="loadedEducation.school = $event"
></app-input-field>
</div>
<div class="col-sm-6 input-wrapper date-picker-input">
<app-input-field
label="Degree"
[value]="loadedEducation.degree"
(updatedValue)="loadedEducation.degree = $event"
></app-input-field>
</div>
</div>
</div>
however the updated data in the fields [value]="loadedEducation.school" (updatedValue)="loadedEducation.school = $event"
don't bind with the sub component so nothing is showing until I refresh and get the data from the DB.
What are the possibilities that I can try to implement?
I tried implementing ngOnChanges, that did not work.