I had one component that consisted of button that triggers function and table that generate elements according to data that i got from service and that function.
But I had to split that component, and now i have only button on one component, and function and table with data on other component.
In first component with button I set EventEmmiter like this:
import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';
import { ConceptService } from "app/services/rest/concept.service";
@Component( {
selector: 'co-calculation',
templateUrl: './co-calculation.component.html',
styles: []
} )
export class CoCalculationComponent implements OnInit {
dataSent: EventEmitter<any> = new EventEmitter();
constructor( private conceptService: ConceptService ) { }
ngOnInit() {}
calculate(){
this.conceptService.calculateCoDatabase().subscribe( (response:any) => {
this.dataSent.emit(response);
}); } }
On other component I have function that I want to triger when I click on button and instead want to set emit to replace service subscription on start of function.
2nd component:
import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';
import { ConceptService } from "app/services/rest/concept.service";
import { CoCalculationComponent } from "app/components/02_top/scm/co-calculation/co-calculation.component";
@Component( {
selector: 'co-database-table',
templateUrl: './co-database-table.component.html',
styles: []
} )
export class CoDatabaseTableComponent implements OnInit {
data;
constructor( private conceptService: ConceptService ) { }
ngOnInit() {
}
generateTable(){
this.conceptService.calculateCoDatabase().subscribe( (response:any) => {
this.data = response;
console.log('data');
//rest of function is irrelevant//
}
I don't know how to trigger function in second component and pass emit from first component instead of service subscribe. Thanks