service.ts
@Injectable { providedIn: ‘root’}
export Service {
public data: any;
public setData(data) {
this.data = data;
}
public getData(): any {
return
this.data}
}
parent.html
<input [(ngModel)]=“model” (ngModelChange)=“onChange(model)”>
parent.ts
import { Service } from ‘./service’;
constructor(private serv: Service) {}
public model: any;
public onChange(some) { this.serv.setData(some); }
child.ts
import { Service } from ‘./service’;
constructor(private serv: Service) {}
public yeah: any;
ngOnInit(){ this.yeah = this.serv.getData() }