Skip to content

docs-bug(material/chips): 'Chips with form control' example does not reflect formControl value #22933

Closed
@jeripeierSBB

Description

@jeripeierSBB

Documentation Feedback

The recently added 'Chips with form control' example (#22814, @devversion) does never show any value at 'Selected keywords'. It seems that the formControl never gets updated.

<p>
  Selected keywords: {{formControl.value}}
</p>

I made a working example here: https://stackblitz.com/edit/angular-o2zelu?file=src/app/chips-form-control-example.ts, but I'm wondering if it should really be necessary to update formControl manually (like I did in stackblitz example)?

export class ChipsFormControlExample {
  formControl = new FormControl(['angular', 'how-to', 'tutorial']);

  addKeywordFromInput(event: MatChipInputEvent) {
    if (event.value) {
      this.formControl.setValue([...new Set([...this.formControl.value, event.value])]);
      event.chipInput!.clear();
    }
  }

  removeKeyword(keyword: string) {
    this.formControl.setValue([...this.formControl.value].filter((entry) => entry !== keyword));
  }
}

Affected documentation page:

https://material.angular.io/components/chips/examples

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions