Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- addLink() {
- //when the plus button is clicked
- const placeholdervalue = this.addForm.get("placeholdervalue").value;
- this.items = this.addForm.get("items") as FormArray;
- this.items.push(this.createItem(placeholdervalue));
- console.log(this.addForm.get("items"));
- }
- createItem(placeholdervalue: string): FormGroup {
- let a = { [placeholdervalue]: "" };
- return this.formBuilder.group(a);
- }
- ngOnInit() {
- this.addForm = this.formBuilder.group({
- items: this.formBuilder.array([]),
- placeholdervalue: ""
- });
- }
- }
- <div class="row">
- <div
- class="col-md-3"
- formArrayName="items"
- *ngFor="
- let item of addForm.get('items').controls;
- let i = index
- "
- >
- <div [formGroupName]="i">
- <mat-form-field class="example-full-width">
- <input
- matInput
- formControlName="" // i want to retrieve it from item
- placeholder=""
- />
- </mat-form-field>
- </div>
- </div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement