2

我已经浏览了 ng2-smart 表,我已经创建了文档中提到的列,以实现列单元格上的功能,我遵循以下链接 https://github.com/akveo/ng2-smart-table/blob/master/ src/app/pages/examples/custom-edit-view/basic-example-button-view.component.ts

但我无法捕捉到其他组件中 ButtonViewComponent 中提到的事件。

import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { ViewCell } from 'ng2-smart-table';
import {Routes, RouterModule, Router} from '@angular/router';
import {Observable} from "rxjs";
@Component({
    selector: 'button-view',
    template: `
    <a (click)="onClick()">{{ renderValue }}</a>
  `,
})
export class ButtonViewComponent implements ViewCell, OnInit {
    renderValue: string;

    @Input() value: string | number = '';
    @Input() rowData: any='Hello';

    @Output() save: EventEmitter<any> = new EventEmitter();
    @Output() sendInformationTOANI: EventEmitter<any> = new EventEmitter();

    ngOnInit() {
        this.renderValue = this.value.toString().toUpperCase();
    }
    constructor(private router: Router){

    }
    onClick() {
        this.save.emit(this.rowData);
        console.log('emit data');
// Here i want to catch this event in other component!!
    }


}

@注意:我尝试过使用@Input 和@Output,但仍然无法捕捉到事件在此先感谢!

4

1 回答 1

2

假设您已经在父组件中声明了列,您可以使用onComponentInitFunction()函数访问子组件的事件。例如

{
  title: "Actions",
  type: "custom",
  renderComponent: ButtonViewComponent,
  onComponentInitFunction :(instance) => {
    instance.save.subscribe(row => {
     //now you can access value from child component here
  });
 }
};
于 2017-10-21T00:07:46.220 回答