1
I am wanting to create dynamic checkboxes. This code should give me, in the field categories
, an object with 3 items false
, but it’s not working. Where am I going wrong?
export class FormPostsComponent implements OnInit {
form: FormGroup;
constructor(
private categoriesService: CategoriesService,
private formBuilder: FormBuilder
) { }
ngOnInit() {
this.form = this.formBuilder.group({
id: [null],
title: [null, [Validators.required, Validators.minLength(3)]],
body: [null, [Validators.required]],
categories: this.buildCategories(),
tags: [null],
imgFeatured: [null],
slug: [null]
});
}
buildCategories() {
const values = this.categoriesService.read().subscribe(
categories => categories.map(
x => new FormControl(false)
)
)
return this.formBuilder.group(values);
}
}