Вы можете создать службу для совместного использования данных между компонентами,
Новая служба, называемая filter-panel.service.ts
file с setter () и getter () метод,
import { Injectable } from '@angular/core';
@Injectable()
export class FilterPanelService {
filterdata: any[];
constructor() { }
get data(): any{
return this.filterdata;
}
set data(val: any){
this.filterdata = val;
console.log(this.filterdata);
}
}
В filter-panel.component.ts
установите значение как,
export class FilterPanelComponent implements OnInit {
public activeFilters: string[];
public text: string="hello world";
constructor(public filterPanelService:FilterPanelService) {
this.activeFilters = [
'Provider: CMS',
'Region: All',
'Provider Group:All',
'Provider: CMS',
'Region: All',
'Provider Group: All'
];
this.filterPanelService.data = this.activeFilters;
}
ngOnInit() {}
}
И в filter-bar.component.ts
получите значение, как ,
export class FilterBarComponent implements OnInit {
@ViewChild('FilterPanelComponent', {static : false}) filterPanel: FilterPanelComponent;
public values1: string[] = ['Philips'];
public values2: string[];
constructor(public filterPanelService: FilterPanelService) {
//this.values2=this.filterPanel.activeFilters;
}
ngOnInit() {
//console.log(this.values2);
console.log('value received ', this.filterPanelService.data);
}
}
Рабочая Stackblitz ..