javascriptangulartypescriptag-gridpass-data

Pass data between 2 components in Angular


I'm trying to pass data from my ag-Grid to a form in a new component by clicking on the row. I could get the data from the row by clicking on the cell via onCellClicked . But i don't know how to pass it to my other component now. here is my 2 interfaces : Ag-Grid

Form

and here is my code : ag-Grid.ts :

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Grid, GridApi } from 'ag-grid-community';
import { AgGridAngular } from 'ag-grid-angular';
import { DealsService } from '../services/deals.service';


import * as moment from 'moment';
import { RouterLinkRendererComponent } from '../router-link-renderer/router-link-renderer.component';
@Component({
  selector: 'app-deals',
  templateUrl: './deals.component.html',
  styleUrls: ['./deals.component.scss']
})
export class DealsComponent implements OnInit {
  showNav = true;

  private gridApi;
  gridOptions = {
    rowHeight :90,
    headerHeight:60,

    defaultColDef: {
      sortable: true
  },
  }
  columnDefs = [


       {
      headerName: 'Deal',
      field:'DEALID',
      cellRendererFramework: RouterLinkRendererComponent,
      cellRendererParams: {
        inRouterLink: '/Repo'
      },
      width:300,
      resizable:true,
      onCellClicked: this.makeCellClicked.bind(this),
      filter: 'agNumberColumnFilter',


       },
       {
        headerName:'Block',
        field:'BLOCKID',
        width:200,
        resizable:true,
        filter: 'agNumberColumnFilter',
        columnGroupShow:'open',
      },
      ],
    },
   
];







rowData : any;

constructor(private service:DealsService) {}

onGridReady(params) {
  this.gridApi = params.api; 
}

getDropDownlist(){
  this.service.getDealsList().subscribe(data => this.rowData = data);

  }



  makeCellClicked(event) {
    console.log(event.data);

  }




ngOnInit() {
this.service.getDealsList().subscribe(data => {
  this.rowData = data;
}); 

}
}

I'm blocked and i do really appreciate your help guys. Thank you!


Solution

  • The shared service was the right solution. How to pass data between two components in Angular 2