Chip input using Reactive Form
The Chips component documentation from the angular material website, describes how to use the MatChipInput directive with a chip-list for adding or removing chips.
I'll show you how you can implement the same component using Reactive Form.
The HTML template:
The TS component file:
The requirements will be accessed in our template with this expression inside the *ngFor of <mat-chip></mat-chip>:
*ngFor="let requirement of form.get('requirements').controls; let i = index;"
In the ChipComponent class, the requirements array is accessed by using this expression:
this.form.get('requirements') as FormArray;
Thanks
This comment has been removed by the author.
ReplyDeleteThanks a lot for this ! :)
ReplyDeleteThank you for sharing. This has been very useful. Saved hours of figuring out.
ReplyDeleteReally super.
ReplyDeleteThank you so much
Very helpful, Thank you so much !! Saved a lot of time.
ReplyDeleteBut it appears you forgot a "d" on your html template, the event called is (removed) not (remove)
Thanks for seeing that
DeleteGreat example. Can you show how to display errors using mat-error? For example, requiring at least one value.
ReplyDelete
Delete[...]
Error sample
its very use full. but i need using data in object how to work with matchips and autocomplete?
ReplyDeletecan u show how to add validations in chip input with formcontrolname
ReplyDeleteThanks and that i have a dandy offer: What Renovation Expenses Are Tax Deductible house renovation stardew
ReplyDelete