Home > Software design >  accessing child components data in other component's array in angular
accessing child components data in other component's array in angular

Time:07-08

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

CodePudding user response:

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?

  • Related