I have skills as FormArray. inside each skill I have rate ControlFormName.
And I have update button. when I click it should patch the values into skills control.
But why nothing happens? it should have input which bind to rate property.
import { Component, VERSION } from "@angular/core";
import { FormGroup, FormArray, Validators, FormBuilder } from "@angular/forms";
@Component({
selector: "my-app",
template: `
form value: {{ form.value | json }}
<br />
<form [formGroup]="form" (ngSubmit)="submit()">
<div formArrayName="skills">
<div
*ngFor="let skill of skills.controls; let i = index"
[formGroupName]="i"
class="skill"
>
<p>
<b>skill : {{ i + 1 }}</b>
</p>
<p>
skill Rate :
<input formControlName="rate" />
</p>
</div>
</div>
<button (click)="update()">update</button>
</form>
`
})
export class AppComponent {
name = "Angular " + VERSION.major;
form = new FormGroup({
skills: new FormArray([])
});
get skills() {
return this.form.get("skills") as FormArray;
}
update() {
this.skills.patchValue([{ rate: 100 }, { rate: 50 }]);
}
submit() {}
}