0

How can I get the initially set FormControl value of a custom component in it's ngOnInit method?

If you set up a form control like so:

testControl = new FormControl("abc123");

Then bind it to your custom component in the html with the attribute like so:

<app-custom-component [formControl]="testControl"></app-custom-component>

How can I access its initial value ("abc123") inside the custom component's ngOnInit() method?

I've already correctly set-up the ControlValueAccessor stuff for my custom component.

Dao Seeker
  • 214
  • 2
  • 11
  • Possible duplicate of [Pass Angular Reactive FormControls to Children Components](https://stackoverflow.com/questions/50883272/pass-angular-reactive-formcontrols-to-children-components) – Vikas Oct 05 '18 at 06:24
  • Do you have a "custom component" (a normal component) or a "custom form control" (a component that implements ControlValueAccessor? – Eliseo Oct 05 '18 at 07:05

1 Answers1

-1

As per my understanding you want to pass value from parent component to child component ?

In the child component

@Input('variable_in_child_component') variable_name

In the parent component You need to pass that value to child component