angulareventemitterviewchild

Difference between EventEmitter and ViewChild('child-form') to get value from child component


In child component, by using EventEmitter we can pass value from child component to parent component.

But I see another case, when we declare ViewChild as below:

@ViewChild('childForm') formComponent: ChildFormComponent;

We also use formComponent to get its data (e.g.: formComponent.listStudent)

Is there any importal point that we need to noticed

Please advices


Solution

  • EventEmitter is primarily used for emitting events from child to parent, while ViewChild is used for accessing child components or elements directly in the parent component. Choose the one that best suits you!