Еще один способ решить эту проблему - создать службу, которая будет содержать переменную массива, а затем внедрить ее в main.component.ts и child.component.ts
custom.service.ts
@Injectable()
export class CustomService {
myArray = [1,2,3,4];
}
main.component.ts
export class MainComponent {
constructor(private customService: CustomService) {}
myArr = this.customService.myArray;
}
child2.component.ts
export class MainComponent {
constructor(private customService: CustomService) {}
myArr = this.customService.myArray;
}