want to show more data in another component when view in detail button is clicked (angular 6)
Create a data sharing service first, here's sample code, you should modify according to your need
Data sharing service
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
@Injectable()
export class DataSharingService {
private title = new BehaviorSubject<string>("");
currentTitle = this.title.asObservable();
setTitle(txt: string){
this.title.next(txt);
}
}
inject this service into your incident component
Data sender component
constructor(
private dataSharingService: DataSharingService
) { }
use this service where you want in your incident component before navigation
this.dataSharingService.setTitle("Your title or data");
Now you surely want to receive data into your incident detail component, for that here's sample code
Data receiver component
title: string;
constructor(private dataSharingService: DataSharingService ) { }
ngOnInit() {
this.dataSharingService.currentTitle.subscribe(data => {
this.title = data;
})
}
Note: Please modify according to your requirement, this service I made to set and get string
title. This service is useful for independent components, without any child-parent relationship.