[英]How should the mat-slider be used inside a form configured with formGroup? Angular Material
I have created a form that has inputs of text type and a mat-slider to get a numeric value我创建了一个具有文本类型输入的表单和一个垫滑块来获取数值
// TS
this.consumptionForm = this.formBuilder.group({
dailyConsumption: ['', Validators.required],
cost: [20, Validators.required],
});
// HTML
<form #form="ngForm" [formGroup]="consumptionForm" novalidate>
<label>Cost</label>
<mat-slider formControlName="cost" [min]="10" [max]="1000" >
</mat-slider>
<div>
<mat-form-field [floatLabel]="true">
<mat-label>Daily Consumption</mat-label>
<input matInput formControlName="dailyConsumption"/>
</mat-form-field>
</div>
</form>
I want the mat-slider to work in conjunction with the rest of the form, and if it is not possible to know which approach is used to use it.我希望垫滑块与表格的 rest 一起工作,如果无法知道使用哪种方法来使用它。
I see that the formControlName is not working我看到 formControlName 不起作用
Here is a working implementation of your issue at Stackblitz .这是您在Stackblitz上的问题的有效实现。
I've added an extra get button to log the form value in the console.我添加了一个额外的获取按钮来在控制台中记录表单值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.