【发布时间】:2020-10-10 17:04:09
【问题描述】:
我正在尝试通过单击行将数据从我的 ag-Grid 传递到新组件中的表单。 我可以通过 onCellClicked 单击单元格从行中获取数据。但我现在不知道如何将它传递给我的其他组件。 这是我的 2 个接口:
这是我的代码: 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;
});
}
}
我被阻止了,非常感谢你们的帮助。 谢谢!
【问题讨论】:
-
您的示例代码非常庞大!尝试将其缩小到会阅读您的人的想法...
-
您要向其传递数据的另一个组件在哪里?
-
试试这个:therichpost.com/…
标签: javascript angular typescript ag-grid pass-data