Upon selecting multiple checkboxes for variants, I am retrieving checked data using the following method:
get selectedIdsFromViolCategoriesFormArray(): string[] {
return this.violCategories
.filter((cat, catIdx) => this.violCategoriesFormArr.controls.some((control, controlIdx) => catIdx === controlIdx && control.value))
.map(cat => cat.value);
}
When I log the output:
console.log('arrViol: '+this.selectedIdsFromViolCategoriesFormArray);
arrViol: Unauthorized access to information, Getting confidential information by supposedly trustworthy person (phishing)
Next, I attempt to assign it to a variable:
this.violation = this.selectedIdsFromViolCategoriesFormArray;
However, I encounter an error:
Type 'string[]' is not assignable to type 'string'
This is my variable. I tried also violation: string;
violation = '';
I also tried:
this.violation = this.selectedIdsFromViolCategoriesFormArray.toString();
and it "works" with a good console.log output, but now..
I want to assign this.violation
to my interface (violation?: any; (I just tried any but nothing))
answers: Answers = {
id: undefined,
name: '',
date: '',
time: '',
violation: this.violation,
description: '',
numofpeople: 0,
};
But despite the correct output in console.log, this.violation
is
undefined
when I try to do
console.log(this.answers.violation)
I do not want to input an array output into my MySql. I simply want a string separated by commas.