Issue
I am working in angular and I am passing 0 as default value in reactive form formControl. The default value is getting reflected in the HTML input. I dont want to show default value in HTML input field at first.
How can I achieve that ?
carnumbers: new FormControl('0', [Validators.minLength(1), Validators.maxLength(2), Validators.pattern("^[0-9]*$")])
Note: the default value must be 0
Solution
If you don't want show default value in View, you should use setValue or patchValue on formControl and pass emitModelToViewChange:false options to it.
carnumbers = new FormControl(null, [Validators.minLength(1),
Validators.maxLength(2), Validators.pattern("^[0-9]*$")]);
ngAfterViewInit(){
this.carnumbers.setValue(0,{emitModelToViewChange:false});
}
Answered By - Chellappan வ
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.