[Solved] ReactiveForm for dynamically updated form entries

If you use ReactiveForm, you need use a FormArray A FormArray can be of FormControl or a FormGroup FormArray of FormControls constructor(private fb:FormBuilder) {} ngOnInit() { //We create an array of FormControl, each question a FormControl let data:FormControl[]=this.questions.map(q=>new FormControl()); this.myform=this.fb.group({ questions:new FormArray(data) }) } //the .html <!–we use *ngIf to show the form only when … Read more

[Solved] Angular 2+, why doesn’t material want to show error message?

*Update To create a customFormControl over a control, we use parent, see an example checkPasswords(): ValidatorFn { //see that the argument is a FormControl return (control: FormControl): ValidationErrors => { //the formGroup is control.parent const group = control.parent as FormGroup; //but we must sure that is defined if (!group) return null; console.log(group.get(“password”).value); let pass = … Read more

[Solved] Disable/Enable submit button in parent component when forms are in child component

In this case, you can simple use a “reference variable” and ask about “reference variable”.emailform.invalid <div> <!–use a “reference variable” to can refered to the component–> <hello #form></hello> <div class=”form-group”> <button class=”btn btn-primary” [disabled]=”form.emailForm?.invalid”>Submit</button> </div> </div> <!–just for “check” –> {{form.emailForm?.value|json}} See that “form” is the component. the component has a variable “emailForm” 1 solved … Read more