Use event emitters and two-way binding like this.
parent component
@Component(){
...
}
export class ParentComp{
parkingLots: Array<any> = [one,two,three];
constructor(){}
}
parent template
<div class="container-fluid">
<div class="row">
<reserved-parking [(data)]="parkingLots"></reserved-parking>
<available-parking [(data)]="parkingLots"></available-parking>
<profile></profile>
</div>
</div>
reserved-parking component
@Component(){
selector: 'reserved-parking',
inputs: ['data'],
outputs: ['dataChange'],
...
}
export class ReservedParking{
data: Array<any>;
dataChange: EventEmitter<Array<any>> = new EventEmitter();
constructor(){}
ngOnInit() {
this.data.push('four');
this.dataChange.emit(this.data);
}
}
available-parking component
@Component(){
selector: 'available-parking',
inputs: ['data'],
outputs: ['dataChange'],
...
}
export class AvailableParking{
data: Array<any>;
dataChange: EventEmitter<Array<any>> = new EventEmitter();
constructor(){}
ngOnInit() {
console.log(this.data);
// you can also update it here and then do
// this.dataChange.emit(this.data); to send it out
}
}
note: import anything required, data is arbitrary change it according to your needs, main thing is to emit the value after modification by doing dataChange.emit(this.data)