0

I need to pass an id of object from one component to another.

<ng-container matColumnDef="actions">
      <mat-header-cell *matHeaderCellDef></mat-header-cell>
      <mat-cell *matCellDef="let user">
         <button mat-icon-button (click)="Edit()"><mat-icon>edit</mat-icon></button>             
      </mat-cell>
</ng-container>

Edit() function opens a form(another component) in which I would like to use something like user.id value. How can I pass the data between components? Is it possible to initialize a value and export it to another component in html code? Or is there any another solution? I would like to add that all the data is provided by service, MongoDB database.

shprei
  • 55
  • 5

1 Answers1

2

If you are passing data from parent component to your child component you should use @input.

In your case you want to pass data from one component to another which are in the same level. i would suggest you to go for shared service.

Look at this answer to get more details.

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396