Javascript 如何在formArray中推送字符串数组?
我需要创建以下内容:Javascript 如何在formArray中推送字符串数组?,javascript,html,angular,Javascript,Html,Angular,我需要创建以下内容: instructions: ['value one' , 'value two' , 'value three']; 我正在使用formArray并首先检查stackblitz上的代码: html: 我正在发送对象数组:check stackblitz console.log 我很高兴 instructors = [{instructs : 'value one'} , {instructs : 'value one'}..] 但我需要发送: instructors
instructions: ['value one' , 'value two' , 'value three'];
我正在使用formArray并首先检查stackblitz上的代码:
html:
我正在发送对象数组:check stackblitz console.log
我很高兴
instructors = [{instructs : 'value one'} , {instructs : 'value one'}..]
但我需要发送:
instructors = ["value one" , "value two"];
你可以试试这个。。我也有同样的问题 制作表格
form = new FormGroup({
instructorsArray: new FormArray([]),
})
get instructors(): FormGroup {
return FormControl('')
}
addInstructors() {
this.instructors.push(this.instructors);
}
有两种方法可以让你继续这样做 1-在save()中使用.map 对于所需的输出,您可以使用
save()
函数中的.map
:
save() {
const instructions = this.filmForm.value.instructions.map(inst => inst. instruction);
console.log(instructions);
}
所需输出为:
["value one" , "value two"]
2-使用标签输入控件,如ng select
您的用例看起来像用于说明的标记控制用例。
有一个流行的图书馆有一个控件
您可以在上查看此库在您的用例中的用法
方法1是最简单的方法,但我建议您在方法2中使用tags control,以获得良好的用户体验。我认为直到第八版才是如此#我不明白?v8呢?我的意思是直到第8版。这可能会帮助您使用rxjs格式化数据:
console.log({instructions:This.filmForm.value.instructions.map(e=>e.instructions)})代码>。看看我的stackblitz:好的,我得到了这个值…但是如何附加到我的表单…这个值…你能解释一下你想用这些值做什么吗?还有,你采用哪种方法?这是什么。佩加迪奥??对不起,这是。教练。推(这是。教练);为了更好地理解,我做了一个改变。
save() {
const instructions = this.filmForm.value.instructions.map(inst => inst. instruction);
console.log(instructions);
}
["value one" , "value two"]