Angular 在FormArray反应形式中设置值不小于0

Angular 在FormArray反应形式中设置值不小于0,angular,angular-reactive-forms,angular-forms,angular4-forms,angular-formbuilder,Angular,Angular Reactive Forms,Angular Forms,Angular4 Forms,Angular Formbuilder,我已成功地将“quantityControl”表单ControlName中输入字段中的值设置为不小于1。然而,我的问题是什么时候在正道上。如何将其设置为不小于0或不应为负数 这是下面的代码和我的stackblitz链接 this.inquiryForm.get('quantityControl').valueChanges.pipe( 过滤器(数量=>数量{ console.log(值); this.inquiryForm.get('quantityControl').setValue(1);

我已成功地将“quantityControl”表单ControlName中输入字段中的值设置为不小于1。然而,我的问题是什么时候在正道上。如何将其设置为不小于0或不应为负数

这是下面的代码和我的stackblitz链接

this.inquiryForm.get('quantityControl').valueChanges.pipe(
过滤器(数量=>数量<1)
).subscribe(值=>{
console.log(值);
this.inquiryForm.get('quantityControl').setValue(1);
});

以更好地理解表单

使用compose()配置具有多个自定义验证的输入字段

this.form = formBuilder.group({
        formControlNameValue:['', Validators.compose([Validators.required, positiveVal ])
        ]});
实施积极评价

static positiveVal(control:Control):{ [key: string]: any; } {
  if (Number(control.value) < 0) {
    return {nonZero: true};
  } else {
    return null;
  }
}
staticpositiveval(control:control):{[key:string]:any;}{
if(数字(控制值)<0){
返回{nonZero:true};
}否则{
返回null;
}
}

该值将不小于1,您的问题是什么???@MuhammedAlbarmawi。我的问题是如何在Formara上实现,以及如何使用*ngIf放置错误消息?我如何访问它?请编辑我的stackblitz。谢谢我的登录表单中的一部分:::用户名是必需的,希望对您有所帮助。
static positiveVal(control:Control):{ [key: string]: any; } {
  if (Number(control.value) < 0) {
    return {nonZero: true};
  } else {
    return null;
  }
}