Receive Array / Create it in Angular2

1

I have to receive an Array in Angular2, since I have not yet done the "send it" thing, I'm simulating that I'm receiving it, the problem is that when using a ngFor it does not do anything.

 @Input() steps: Array<number>[4]; //Así no funciona

  //  steps: Array<number> = [1, 2, 3, 4]; //asi si

   Supuestamente tendría que sacar 4 veces 'ey'

   <div>
    <div class='line'></div>
    <clr-icon *ngFor="let step of steps; let i = index" shape="circle" 
    [ngClass]="'circle' + (i + 1 )" size="36">
      ey
    </clr-icon>
  </div>
    
asked by EduBw 23.04.2018 в 14:03
source

2 answers

1

What you are looking for is to create an array on x length ?. If that is the case you can create the array using new Array (array tamanho)

miArray = new Array(4);
    
answered by 27.04.2018 / 21:27
source
1

According to TypeScript documentation , the way you try to do it is not correct (create the array passing it a size), and the one you have commented on is the one that works.

The values within [] are each of the elements and not the size of the array.

let list: Array<number> = [1, 2, 3];

Maybe you're confused about how an array is instantiated in C # ?

int[] array = new int[4];
    
answered by 23.04.2018 в 14:13