Dash
Dash

Reputation: 737

Get child value on the parent without triggering eventemiiter in angular v6

Angular v6.

Have a Parent component which has a send button.

A Card Component in which multiple inputs are present list/ comments/checkbox etc.

Parent component loops and calls the card component.

Example:

<div>
   <div *ngFor="3 times">
      <card-component></card-component>
   </div>
</div>

Is there any way without clicking any thing to get the values of the child component while pressing the send button on the parent.

Eventemitter requires an action like a click on the child, but is there any way to get the child component details when clicking the send button on the parent.

Rough image of the UI

Upvotes: 1

Views: 57

Answers (1)

Prachi
Prachi

Reputation: 3574

In parent component ts, use:

@ViewChild(ChildComponent) child: ChildComponent;

And use it to access its properties and methods, after the child component gets properly rendered:

console.log(this.child.your_child_variable);

Upvotes: 1

Related Questions