如題...
errors只列印出required
試過minLength(),maxLength(),parttern都列印不出來...
是哪裡寫錯了嗎...??
列印出的結果---
startNum: FormControl
errors:
required: true
__proto__: Object
pristine: true
status: "INVALID"
程式碼
html
<form  [formGroup]="form">
<input 
type="number" 
class="input" 
formControlName="startNum">
ts
public form!: FormGroup;
constructor(private fb: FormBuilder,) {}
ngOnInit(): void {
    this.form = this.fb.group({
     startNum: new FormControl('',{
        validators: [
          Validators.minLength(4),
          Validators.required,
          Validators.pattern('\d{7}')
        ],
      }),
    });
  }
找不到問題出在哪@@~感恩~
問題出在 <input type="number" ...>
minLength 是判斷字串長度,也就是 "123".length 這種,但 type=number 的設定會讓你拿到數值,判斷 123.length 是錯誤的