如何在angular 2中动态获取单选按钮值?

如何在angular 2中动态获取单选按钮值?,angular,Angular,需要从数组中动态显示单选按钮值,并获取它的值,根据该值我需要显示。请在下面查找代码 html 有了这个,我得到了苹果和芒果的单选按钮。需要得到所选单选按钮的值(在赋值[(ngModel)],值),并需要根据个人选择显示另一个div。 请在这方面指导我您可以使用[value] <div *ngFor="let fruit of fruits"> <input type="radio" formControlName="options" [value]="fruit">

需要从数组中动态显示单选按钮值,并获取它的值,根据该值我需要显示
。请在下面查找代码

html

有了这个,我得到了苹果和芒果的单选按钮。需要得到所选单选按钮的值(在赋值[(ngModel)],值),并需要根据个人选择显示另一个div。
请在这方面指导我

您可以使用
[value]

<div *ngFor="let fruit of fruits">
    <input type="radio" formControlName="options" [value]="fruit">
    {{fruit}}
</div>`

{{水果}
`
}

fruits : string[] = ["apple", "mango"];
<div *ngFor="let fruit of fruits">
    <input type="radio" formControlName="options" [value]="fruit">
    {{fruit}}
</div>`
<div *ngFor="let fruit of fruits">
<input type="radio" [value]="fruit" 
(change)="selectedFruitValue(fruit)">
{{fruit}}
</div>

in your ts file
first define a variable
i.e
fruitValue:string
selectedFruitValue(fruit){

this.fruitValue = fruit;

//for checking purpose
 console.log('fruit value is':+this.fruitValue);