Create a shared interface and set value from child and get from parent as below:
Interface:
import {Injectable} from "@angular/core";
export interface SharedModel {
Name: string;
}
@Injectable()
export class Shared {
SharedComponent: SharedModel = {
Name: ''
};
constructor() {
}
}
Parent/Child Component:
import {Shared, SharedModel} from '../Shared';
public sharedData: SharedModel;
constructor(private sharedResource: Shared) {
this.sharedData = sharedResource.SharedComponent;
}
Set Value:
this.sharedData.Name="Sandip Patel";
Get Value:
console.log(this.sharedData.Name);