For example, I have another array as follows:
var array = ['喜欢','不喜欢','非常喜欢','超级喜欢','喜欢得不得了'];
html template
<p class="like" *ngFor="let e of array">
<input type="checkbox" name="like" value="{{e}}">
</p>
<p class="youselect"></p>
How do I implement it? After selecting one of the checkboxes, the selected content can be displayed in p.youselect. If it is multiple selection, it will be displayed as an array or comma separated form
For example, if I select "Like", "I like it very much", then p.youselect will display:
"I like it, I like it very much"
You can use formArray and other methods, but I didn't implement it during use. I hope God can help!
Thank you for the invitation. Based on the data structure you gave me, it is recommended to use the following data structure (when submitting the form, the corresponding id item is generally submitted):
For details, please refer to - handling-multiple-checkboxes-in-angular-forms
The simple sample code is as follows:
Personally, I feel like it’s easier not to use Forms. . .
Written a Fiddle: https://jsfiddle.net/phnjg6hf/4/
HTML:
JS: