Trying to pass the array value from the parent component to the child component using httpclient get method. So, I have used an input decorator. But, In my code, I am not able to pass the array value. Because the child component is loaded before the parent component. That's why i am not able to pass the data inside the get method. How to resolve this issue?
app.component.ts:
public allData = [];
constructor(private httpClient: HttpClient) {}
ngOnInit(): void {
this.httpClient.get<string[]>('assets/data.json').subscribe((data) => {
this.allData = data;
console.log('GetData');
console.log(data);
});
}
auto.component.ts:
@Input() data: Array<string> = [];
public rateData:any;
constructor() {
}
ngOnInit(): void {
console.log("thisdata");
console.log(this.data)
this.rateData =this.data;
}
Demo: https://stackblitz.com/edit/angular-ivy-1jw62m?file=src%2Fapp%2Fauto%2Fauto.component.ts