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);
Use Event Emitter. It will call parent component method and you can pass your any object in that method call as below:
Child Component:
import {ViewChild, Component, Output, EventEmitter} from "@angular/core";
@Output() RefreshParentGridView = new EventEmitter();
public Close(): void {
let myObject:any; //Your object which pass in parent
this.RefreshParentGridView.emit(myObject);
}
Parent Component: register output event as below
HTML
<childTeg (RefreshParentGridView)= "RefreshGridView($event)"></childTeg>
Backend Code
public RefreshGridView(model: any)
{
}