Answer the question
In order to leave comments, you need to log in
How to create a reactive form in Angular using dumb components?
Hello everyone!
Please tell me, I am creating a login page component, I want to use reactive forms. But I have a list of dumb components that I have to use. I have a form component:
<form [formGroup]="loginForm" (ngSubmit)="loginUser()">
<div>
<label for="email">Email:</label>
<app-input type="text" ></app-input>
</div>
<div>
<label for="password">Password:</label>
<app-input type="text" ></app-input>
</div>
<button type="submit">login</button>
</form>
<input
type="text"
[(ngModel)]="value"
(input)="this.valueChange.emit(this.value)"
>
import {Component, EventEmitter, Input, Output} from '@angular/core';
@Component({
selector: 'app-input',
templateUrl: './input.component.html',
styleUrls: ['./input.component.css']
})
export class InputComponent {
@Input() value = '';
@Output() valueChange = new EventEmitter<string>();
}
Answer the question
In order to leave comments, you need to log in
ControlValueAccessor
https://medium.com/@maks.zhitlov/custom-form-contr...
https://tyapk.ru/blog/post/angular-custom-form-fie...
and level up
https:/ /blog.angularindepth.com/reducing-the-forms...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question