【问题标题】:Event Emitter @output on gridOptions.onRowDoubleClickedgridOptions.onRowDoubleClicked 上的事件发射器 @output
【发布时间】:2018-05-20 12:48:15
【问题描述】:

我正在尝试通过双击一行从 ag-grid 中恢复客户端。 我正在使用 angular 5 和 ag-grid。

ag-grid 是一个名为 grid_client 的组件中的子组件,当我双击给定行时,我已将其注入名为quotation-creation 的父组件中,我可以控制子组件中单击的行,但在父组件中,什么都没有出现!这是我的代码: 子级:客户端网格组件

@Output() clientRow  : EventEmitter<any> = new EventEmitter();
 createGridOptions() {
     this.gridOptions = <GridOptions>{};
     this.gridOptions.onRowDoubleClicked = this.clientAdd;
    }
 clientAdd=(row)=>{
    this.clientRow.emit(row.data);
    console.log(row.data)// i could be sure that the row is displayed in the console
 }

之后我在 Parent 中调用了我的活动:

<h3>List of client</h3>
        <app-grid-client (clientRow)='rowClient($event) >//to display the grid and recuperate the event

    </app-grid-client>

在父组件的ts中

rowClient( row ) {
    console.log(row);
}

父组件中没有出现任何错误或未定义。

能否请您帮忙知道为什么我没有在父级中点击该行?

【问题讨论】:

  • 如果答案对您有帮助,请告诉我

标签: angular ag-grid


【解决方案1】:

您的 HTML 中似乎有错误,您错过了结束 ',您的 JavaScript 中的内容似乎已正确绑定。

请从以下位置更改:

<app-grid-client (clientRow)='rowClient($event) >//to display the grid and recuperate the event

</app-grid-client>

<app-grid-client (clientRow)='rowClient($event)' >//to display the grid and recuperate the event

</app-grid-client>

【讨论】:

  • 嗨,哈里斯,谢谢您的回答,是的,我复制代码时出错了,抱歉,但仍然一无所获。有没有其他方法可以恢复从父母到孩子的数据?
  • 你在clientAdd()方法中看到一行了吗?
  • 是的,我可以在控制台中显示我双击的行,它是一个由所有客户信息组成的对象。我试着做一些事情,我只是把名字放在一个新事件中:@Output() firstn: EventEmitter = new EventEmitter();然后我只发出名字:clientAdd=(row)=>{ console.log(row.data);让 firstName =row.data.firstName this.firstn.emit(firstName);控制台.log(名字);在 Parent 我可以恢复我的对象的名字: HTML:
  • 好的,您可以尝试发出一个可以从您的客户端信息创建的对象,如下所示:.emit({ Foo: true, FooBar: 1, SomeProperty: 100}) 让我知道是否这样帮助我会更新答案甚至 .emit({Object: data})
  • 我想我找到了为什么使用变量 clientRow 不起作用,因为不知何故我在我的 ngOninit 中再次初始化了它: ngOnInit() { this.clientRow = new EventEmitter() ; /// 我猜这引起了一个问题,所以我再次尝试发出 Object 行,现在它工作正常感谢您的帮助 Haris :)
猜你喜欢
  • 2017-12-04
  • 2019-04-19
  • 1970-01-01
  • 2020-07-11
  • 1970-01-01
  • 1970-01-01
  • 2021-09-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多