Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.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
Javascript 角度形式的Toastr消息_Javascript_Angular_Angular Material - Fatal编程技术网

Javascript 角度形式的Toastr消息

Javascript 角度形式的Toastr消息,javascript,angular,angular-material,Javascript,Angular,Angular Material,我有一个棱角形。因此,在字段中,我已设置为要验证的STR消息,以便不会提交空字段。它工作正常,并显示toastr消息,但当我输入两个空格并提交表单时,它仍然接受并提交表单。我想要一条toastr消息,当我们输入两个空格或空空格并提交时,显示表单字段为空。有什么方法可以对其进行排序吗 ngOnInit(): void { this.customerForm = this.fb.group({ name: ['', Validators.required], custom

我有一个棱角形。因此,在字段中,我已设置为要验证的STR消息,以便不会提交空字段。它工作正常,并显示toastr消息,但当我输入两个空格并提交表单时,它仍然接受并提交表单。我想要一条toastr消息,当我们输入两个空格或空空格并提交时,显示表单字段为空。有什么方法可以对其进行排序吗

    ngOnInit(): void {
  this.customerForm = this.fb.group({
    name: ['', Validators.required],
    customer_id: ['', Validators.required],
   
    
  })

}
   if (this.customerForm.value.customer===""){
    this.toastr.error('Add customer field' ,{timeOut: 1500});
    return false;
  }



       <td>
<mat-form-field>
    <mat-label>Name</mat-label>
    <input matInput placeholder="Name" formControlName="name" autocomplete="off" required>
</mat-form-field></td>
ngOnInit():void{
this.customerForm=this.fb.group({
名称:['',验证器。必需],
客户id:['',验证器。必需],
})
}
if(this.customerForm.value.customer==“”){
this.toastr.error('addcustomer字段',{timeOut:1500});
返回false;
}
名称
< /代码> 您可以在将字符串与空白字符串进行比较之前,从字符串的开始和结束移除空白。

if (this.customerForm.value.customer.trim() === ""){
    this.toastr.error('Add customer field', {timeOut: 1500});
    return false;
}

嘿,谢谢,这很有效。如果用户在toastr的表单字段中最多只能输入20个字符,您能提供帮助吗?任何超过20个字符的内容都应该显示toastr消息
this.customerForm.value.customer.trim().length>20