【问题标题】:angular2 ng2-smart-table :issue while catch the data from custom button eventangular2 ng2-smart-table:从自定义按钮事件捕获数据时发出
【发布时间】:2017-10-21 08:07:46
【问题描述】:

我已经浏览过 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 但仍然无法捕获事件 提前致谢!!

【问题讨论】:

    标签: angular ng2-smart-table


    【解决方案1】:

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

    {
      title: "Actions",
      type: "custom",
      renderComponent: ButtonViewComponent,
      onComponentInitFunction :(instance) => {
        instance.save.subscribe(row => {
         //now you can access value from child component here
      });
     }
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多