-
-
Save jorroll/ddbf8e9546c65d36d0940cfb90f33f1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'app-user-form', | |
template: ` | |
<div> | |
<label>First name</label> <input formControlName="firstName" required /> | |
</div> | |
<div> | |
<label>Last name</label> <input formControlName="lastName" required /> | |
</div> | |
<app-email-address-input formControlName="emailAddress" required> | |
</app-email-address-input> | |
`, | |
providers: [ | |
{ | |
provide: NG_CONTROL_ACCESSOR, | |
useExisting: forwardRef(() => UserFormComponent), | |
multi: true, | |
}, | |
{ | |
provide: NG_CONTROL_CONTAINER_ACCESSOR, | |
useExisting: forwardRef(() => UserFormComponent), | |
}, | |
], | |
}) | |
export class UserFormComponent implements ControlContainerAccessor<FormGroup> { | |
readonly control = new FormGroup({ | |
firstName: new FormControl('', { | |
validators: Validators.required, | |
}), | |
lastName: new FormControl('', { | |
validators: Validators.required, | |
}), | |
emailAddress: new FormControl('', { | |
validators: [Validators.required], | |
}), | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment