How to pass two parameters to EventEmitter in Angular 9 ? Last Updated : 05 Jun, 2020 Comments Improve Suggest changes Like Article Like Report In Angular, we can transmit the data in both directions i.e. inside: to the child component and outside: to the parent component. For sending data to the child component, we use property binding and for the latter we use EventEmitter. In this article, we will talk about the EventEmitter directive and how can we pass 2 parameters in it. Let's take a look at EventEmitter source code: javascript export declare class EventEmitter<T> extends Subject<T> { __isAsync: boolean; constructor(isAsync?: boolean); emit(value?: T): void; subscribe( generatorOrNext?: any, error?: any, complete?: any): any; } It is clearly visible that in the emit method only one parameter of type T can be passed, so we cannot pass two parameters directly into it. Instead, we can make an object containing all the parameters and pass the object as a single entity. Approach: EventEmitter allows us to emit any type of object, so we will take advantage of it.For passing the parameters, we will wrap all the parameters inside the curly brackets (this will combine them as a single object) and pass it to the emit method.To receive the parameters in the parent component, we will make a similar type of object and update its value with that of the received object. Syntax: @Output() sendobject = new EventEmitter<any>(); this.sendobject.emit({stringval, numval, ...}); Example: We will create two properties in child component and receive them in parent component by using EventEmitter. Code for the child component: javascript import { Component, OnInit, EventEmitter, Input, Output } from '@angular/core'; @Component({ selector: 'app-test', template: ` <h2>child component<h2> <h4>{{name}}</h4> <h4>{{age}}</h4> <button (click) = "send_name_age()">send data</button> `, styles: [] }) export class TestComponent { constructor() { } public name = "geek2"; public age = 22; /* we will define the type of the an object that will be emitted.*/ @Output() public data = new EventEmitter<{name:string, age:number}>(); send_name_age() { /* we will wrap the parameters to be sent inside the curly brackets.*/ this.data.emit({name:this.name, age:this.age}); } ngOnInit(): void { } } Code for the parent component: javascript import { Component } from '@angular/core'; @Component({ selector: 'app-root', template: ` <div style="text-align: center;" > <h1>parent component</h1> <h2>{{model.name}}</h2> <h2>{{model.age}}</h2> </div> /* The data that is sent by the child component will be received in the */ /* Parent component as a parameter for change_name_age method. */ <app-test (data) = "change_name_age($event)" > </app-test> `, styleUrls: [] }) export class AppComponent { /* Create a model of the type that is emitted by the child component to receive it.*/ public model = { name: "geek1", age: 24 } change_name_age(data) { /* Update the current model with the value sent by the child component. */ this.model = data; } } Output: Successfully received both age and name from child component in the parent component. Before receiving name and age: Before receiving data Name and age in the parent component is updated after receiving it from child component.After receiving data Comment More infoAdvertise with us Next Article How to pass two parameters to EventEmitter in Angular 9 ? V vaibhav19verma Follow Improve Article Tags : Web Technologies AngularJS AngularJS-Misc Similar Reads How to pass multiple parameter to @Directives in Angular ? Angular directives are TypeScript classes decorated with the @Directive decorator. These are powerful tools for manipulating the DOM and adding behavior to elements. They can modify the behavior or appearance of DOM elements within an Angular application. Directives can be broadly categorized into t 3 min read How to pass a parameter to an event handler or callback ? In React, to pass a parameter to an event handler or callback simply means to execute that function or code when the event is triggered. It links the events to the respective functions. Prerequisites:React JSEvent HandlersReact JS Class ComponentApproachWe will define a function to create a window a 2 min read How to pass data from Parent to Child component in Angular ? We can use the @Input directive for passing the data from the Parent to Child component in AngularUsing Input Binding: @Input - We can use this directive inside the child component to access the data sent by the parent component. Here app.component is the Parent component and cdetail.component is th 2 min read How to Get All Route Params/Data in Angular? In Angular, managing route parameters and extracting data from routes is important for creating dynamic and responsive web applications. Route parameters allow you to pass information in URLs, and accessing this data enables your application to make decisions and render content dynamically. This art 4 min read How to submit form on pressing Enter with Angular 9? To submit a form in angular we have the following options: Create a button to submit the form.Assign a key to submit the formOr we can do both. In this tutorial, we will see how to use a specific key(Enter in this case) to submit a form. Approach: We can use angular keydown event to use Enter key as 2 min read How To Get The URL Parameters Using AngularJS? In AngularJS, retrieving URL parameters is essential for managing dynamic content and user interactions based on the URL state. In this article, we'll learn various approaches to achieve this.Table of ContentApproach 1: Using ActivatedRoute ServiceApproach 2: Using Router ServiceApproach 3: Using UR 3 min read How to communicate from parent component to the child component in Angular 9 ? Angular makes the communication between components very easy. In this article, we will learn how to communicate from a parent component to the child component. Approach: Let's create two components: parent child In the parent component, declare the property that you want to receive in the child comp 2 min read Passing data from Child to Parent Component in Angular In Angular, passing data from a child component to its parent component involves emitting events. Essentially, the child component emits an event containing the data that the parent component needs to receive. This is typically achieved using Angular's EventEmitter class, where the child component e 3 min read How to Subscribe to an Observable in Angular? In Angular, managing data streams effectively is important, especially when dealing with asynchronous operations. Observables, a core part of the RxJS library used in Angular, are powerful tools for handling these data streams. In this article, we will explore how to subscribe to Observables in Angu 4 min read How to Register Services with the Providers Array in Angular? To register services with the provider's array in Angular, you first generate a service using the Angular CLI. Then, you can register the service in the providers array within the module (app.module.ts) or component where the service is needed. Once registered, the service can be injected into any c 3 min read Like