Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用ngModel的动态单选按钮双向绑定-Angular 6_Angular_Radio Button_Angular Ngmodel - Fatal编程技术网

使用ngModel的动态单选按钮双向绑定-Angular 6

使用ngModel的动态单选按钮双向绑定-Angular 6,angular,radio-button,angular-ngmodel,Angular,Radio Button,Angular Ngmodel,我正在生成动态单选按钮,这些按钮将全部合并到表单提交中,而不是单独提交。但是,我需要将它们分别绑定到组件中的特定值,而我不知道如何做 我已经在stackoverflow上看到了关于这个主题的其他相关帖子,但它们似乎都没有帮到我 这是我的密码: 任何帮助都将不胜感激。在组件中获取数组的新变量: private radioButtonValues : Array<any> = []; 如果您需要一些操作,还可以使用ngModelChange事件获得更多功能 <input ty

我正在生成动态单选按钮,这些按钮将全部合并到表单提交中,而不是单独提交。但是,我需要将它们分别绑定到组件中的特定值,而我不知道如何做

我已经在stackoverflow上看到了关于这个主题的其他相关帖子,但它们似乎都没有帮到我

这是我的密码:



任何帮助都将不胜感激。

在组件中获取数组的新变量:

private radioButtonValues : Array<any> = [];
如果您需要一些操作,还可以使用
ngModelChange
事件获得更多功能

<input type="radio" class="one" 
       id="{{ i }}_{{ candidate.user._id }}_{{post.id}}_{{ candidate.date}}" 
       name="{{post.id}}" 
       [value]='candidate.user._id' 
       [(ngModel)]="radioButtonValues[i]" 
       (ngModelChange)='changeEventInRadioButton($event)'>
最后对表单提交进行检查

onSubmit(){
    console.log(this.radioButtonValues);
}

在组件中获取数组的新变量:

private radioButtonValues : Array<any> = [];
如果您需要一些操作,还可以使用
ngModelChange
事件获得更多功能

<input type="radio" class="one" 
       id="{{ i }}_{{ candidate.user._id }}_{{post.id}}_{{ candidate.date}}" 
       name="{{post.id}}" 
       [value]='candidate.user._id' 
       [(ngModel)]="radioButtonValues[i]" 
       (ngModelChange)='changeEventInRadioButton($event)'>
最后对表单提交进行检查

onSubmit(){
    console.log(this.radioButtonValues);
}

它不是已经绑定到具有post.id的特定值了吗?不确定您想要什么,但确实有帮助吗?它是否已经绑定到具有post.id的特定值?不知道你想要什么,但是有帮助吗?谢谢Nasiruddin Saiyed,ngModel中的索引修复了它。虽然我必须使用公共RadioButtonValue:Array=[];为了使其可访问性,ngModel中的索引修复了它。虽然我必须使用公共RadioButtonValue:Array=[];让它变得容易接近