accessing child components data in other component's array in angular

Issue

I’m trying to set the 5 in Array(5) to another variable in this code:

What I’m trying to do:

export class HelloComponent {
  @Input() page: number;

  active = 0;

  pages;

  constructor() {
    this.pages = Array(this.page) //rather than Array(5) 
      .fill(0)
      .map((x, i) => i);
    this.pages.pop();
  }

  get currentPage() {
    return this.active;
  }
}

Here’s the stackblitz

Solution

Honestly, I’m not sure of what you’re trying to do here, but have a look at this fork of your StackBlitz demo.

Is this what you want to do?

Answered By – Vasileios Kagklis

Answer Checked By – Gilberto Lyons (AngularFixing Admin)

Leave a Reply

Your email address will not be published.