I have the following problem-
component A:
<!-- LIST OF URLs-->
<exl-file-list
*ngIf="hasLinks()"
listTitle="Added links:"
[expandable]="editableFiles"
expandAllButton="Edit metadata"
(edit)="onLinkEdit($event)"
(expandAll)="allLinksEditable = !allLinksEditable"
(removeAll)="onRemoveAllLinks()">
<!-- URL items -->
<exl-file-list-item
*ngFor="let link of depositFormDataService.mainForm.value.links let index = index"
[item]="link"
[index]="index"
(remove)="onLinkRemove($event)"
(edit)="onLinkEdit($event, index)">
<!-- metadata of each URL -->
**<esp-deposit-link-metadata
[index]="index">
</esp-deposit-link-metadata>**
</exl-file-list-item>
</exl-file-list>
component B- esp-deposit-link-metadata:
<div class="metadata-container">
<mat-form-field class="hasnt-underline">
<mat-label>Description</mat-label>
<textarea
matInput
[(ngModel)]="description"
**(ngModelChange)="onChangeDescription()"
** #textarea placeholder="Describe the link"
matTextareaAutosize></textarea>
</mat-form-field>
</div>
onChangeDescription
method, updated my formGroup
in depositFormDataService.mainForm.links
onChangeDescription(){
this.depositFormDataService
.updateLinkDescription(this.index,this.description);
}
it's content:
updateLinkDescription(index, description){
const link = this.links.at(index) as FormGroup;
link.setControl('description', new FormControl(description));
}
depositFormDataService.mainForm holds the links as FormArray. link is an object with three formControls that one of them is 'description'.
Each time that onChangeDescription()
is called the constructor
s of exl-file-list-item
and esp-deposit-link-metadata
are called and all the view is refreshed, and I have no reason why.