Reputation: 180
I have been gone through ng2-smart table ,I have created columns as mentioned in document for achieving the functionality on column cell I have followed below link https://github.com/akveo/ng2-smart-table/blob/master/src/app/pages/examples/custom-edit-view/basic-example-button-view.component.ts
But I am unable to catch the event which has mentioned in ButtonViewComponent in other components.
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!!
}
}
@Note: I have tried using @Input and @Output but still not able to catch event Thanks in Advance!!
Upvotes: 2
Views: 2569
Reputation: 1123
Assuming that you have declared your columns in the Parent Component, you can access your child component's event using onComponentInitFunction() function. For instance
{
title: "Actions",
type: "custom",
renderComponent: ButtonViewComponent,
onComponentInitFunction :(instance) => {
instance.save.subscribe(row => {
//now you can access value from child component here
});
}
};
Upvotes: 2