I have a dynamic form controlled by a Parent component, with an array of Child DTOs, that is rendered using ngFor, and those Child Components are passed the DTO and use their own template. Something like:
Parent Html:
<div class="row parameter-list" *ngFor='let parameter of parameters'>
<div class="col-md-12">
<parameter-list-item
[parameter]="parameter"
[types]="types"
[events]="eventsSubject.asObservable()"
(onDelete)="onDeleteHandler($event)">
</parameter-list-item>
</div>
</div>
Parent Component:
@Input()
parameters: Parameter[];
Child Html:
<input type="text" [(ngModel)]="parameter.Name" [disabled]="readonly">
<input type="text" [(ngModel)]="parameter.Description" [disabled]="readonly">
Child Component:
constructor() {
this.readonly = true;
}
readonly: boolean;
@Input()
parameter: Parameter;
DTO:
export class Parameter {
Name: string,
Description: string) { }
}
When I want to change the list, by adding a Parameter to the Parent component, I am doing the following with a (click) handler:
addParameter(): void {
console.log("ParameterListComponent.addParameter()");
let name = "Name" + this.parameters.length;
let parameter = new Parameter(
name,
"Description");
this.parameters.unshift(parameter);
}
Essentially letting the unshift trigger the proper lifecycle hooks and whatnot.
What I need to know is if I can somehow communicate with the newly created child component and set it's readonly boolean to false..