I have a parent component, and three child components
I send data in these three components, and i use setTimeout to control the time for sending the data
The first component lasts 5000 milliseconds
The second component lasts 10000 milliseconds
The third component lasts 15000 milliseconds
In each child component i used a spinner, this spinner hides when the data arrives to the component
The problem is that when the data arrives to the first component, all the spinners for the other components hide too
export class AppComponent {
public dataOne: string;
public dataTwo: string;
public dataThree: string;
constructor() {
setTimeout(() => {
this.dataOne = "one";
}, 5000);
setTimeout(() => {
this.dataTwo = "two";
}, 10000);
setTimeout(() => {
this.dataThree = "three";
}, 15000);
}
}
<one [data]="dataOne"></one>
<two [data]="dataTwo"></two>
<three [data]="dataThree"></three>
export class OneComponent implements OnChanges {
@Input() data: string;
constructor(private spinner: NgxSpinnerService) {
this.spinner.show();
}
ngOnChanges(changes: SimpleChanges) {
if (changes["data"] && changes["data"].currentValue) {
this.spinner.hide();
console.log(changes["data"].currentValue);
}
}
}