Javascript 如何计算已选中的mat单选按钮的数量?有棱角的
我想检查表单中单选按钮的编号,以保存该编号并将其传递给进度条Javascript 如何计算已选中的mat单选按钮的数量?有棱角的,javascript,html,angular,Javascript,Html,Angular,我想检查表单中单选按钮的编号,以保存该编号并将其传递给进度条 <mat-radio-group name="clientID" [(ngModel)]="model.clientID"> <mat-radio-button *ngFor="let n of CONSTANTS.CLIENT" [value]="n.value"> {{n.display}} </mat-radio-button> </mat-radio-g
<mat-radio-group name="clientID" [(ngModel)]="model.clientID">
<mat-radio-button *ngFor="let n of CONSTANTS.CLIENT" [value]="n.value">
{{n.display}}
</mat-radio-button>
</mat-radio-group>
您可以检查单选按钮的更改事件,并根据该事件触发事件并读取如下值: .ts .html
{{n.display}
{{progressnumber}}}%
工作示例:
您可以检查单选按钮的更改事件,并根据该事件触发事件并读取如下值: .ts .html
{{n.display}
{{progressnumber}}}%
工作示例:
由于这些是单选按钮,您只能选中1个(或不选中),对吗?或者你的无线电值是数字,你想要检查的数字值?如果是这样,您的单选组应该有一个“value”属性,其中包含您选中的值。这可能会有帮助=@Flo您只能检查1或无正确:D并且值不是数字,因为这些是单选按钮,您只能检查1(或无),对吗?或者你的无线电值是数字,你想要检查的数字值?如果是这样的话,您的无线组应该有一个“value”属性,其中包含您检查的值。这可能会有帮助=@Flo您只能检查1或不检查。这是正确的:D,值不是数字
<div>
<p>{{progressnumber}}%</p>
</div>
<mat-progress-bar mode="determinate" value="{{progressnumber}}"></mat-progress-bar>
progressnumber:number = 70;
import { Component } from '@angular/core';
import { MatRadioChange } from '@angular/material';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
progressnumber:number = 70;
clientID = 70; // I don't know what is your model.clientID is,
// I just use it clientID and fixed a initial value
// of it. You can use yours
clients : any[] = [
{value:70, display:'client 1'},
{value:40, display:'client 2'},
{value:50, display:'client 3'}
]
radioChange(event : MatRadioChange){
this.progressnumber = event.value
}
}
<mat-radio-group name="clientID" [(ngModel)]="clientID">
<mat-radio-button *ngFor="let n of clients" [value]="n.value" (change)="radioChange($event)">
{{n.display}}
</mat-radio-button>
</mat-radio-group>
<div>
<p>{{progressnumber}}%</p>
</div>
<mat-progress-bar mode="determinate" value="{{progressnumber}}"></mat-progress-bar>