// Parent-Component
public inputToChild: Object;
// Parent-HTML
<child [data]="inputToChild"> </child>
//Child-Component
@Input() data;
ngOnChanges(changes: { [property: string]: SimpleChange }) {
// Extract changes to the input property by its name
let change: SimpleChange = changes['data'];
// Whenever the data in the parent changes, this method gets triggered
// You can act on the changes here. You will have both the previous
// value and the current value here.
}
// SharedService
subject: Subject<Object> = new Subject<Object>();
// Parent-Component
constructor(sharedService: SharedService)
this.sharedService.subject.next(data);
// Child-Component
constructor(sharedService: SharedService) {
this.sharedService.subject.subscribe((data) => {
// Whenever the parent emits using the next method,
// you can receive the data in here and act on it.
});