If there is no data in the table, I am getting undefined from service but I want to display default value in formControl in that case. if data is there then working fine...Please help me and suggest what I need to do.
When you create the group and controls inside it , you can also initialize them.
fb
is the FormBuilder
fb.group({
yourControl: [0, Vaidators.required] // '0' is the default value
});
You can try with default value in form control.
myForm: FormGroup;
ngOnInit() {
this.myForm = this.fb.group({
name: ["test", [Validators.required, Validators.maxLength(30)]],
address: this.fb.group({
pin: ["123456", Validators.required]
})
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With