1

I have a variable inside the component.ts and i want to generate select options based on the integer.

Say i have a variable

total =10;

this.totalArray = Array(this.total).fill().map((x,i)=>i); 

component.html

@Component({
  template: `
    <ul>
      <li *ngFor="#number of totalArray">{{number}}</li>
    </ul>
  `
})
export class SampleComponent {
  (...)
}

but this gives an error, Supplied parameters do not match any signature of call t arget

1
  • What code causes this error? Commented May 17, 2017 at 12:35

1 Answer 1

1

The *ngFor syntax is let number of totalArray. #number of totalArray is invalid since about year:

<ul>
  <li *ngFor="let number of totalArray">{{number}}</li>
</ul>
Sign up to request clarification or add additional context in comments.

10 Comments

this.totalArray = Array(this.total).fill().map((x,i)=>i);
I'm pretty sure the error comes from somewhere else. Your code doesn't contain a t. Your *ngFor syntax is still invalid though.
I do agree with @GünterZöchbauer. However, it is worth mentioning that .fill, in this case, even without an argument, works. Maybe typescript doesn't like? jsfiddle.net/7ockyxmz I've never seen .fill used in this way, but for sure the *ngFor loop is not set up correctly, unless you're using a very old angular 2 version (2015?). Also worth noting that .fill(1) gives the same as .fill(). Not sure why, but it may be a temporary workaround if that's the issue.
JS is quite forgiving. It probably just uses undefined as value which is later replaced anyway with map().
Yes, I've got it. Basically, Array(10) is [undefined x 10]. Then, .fill() creates key->value pairs for the 10 undefined. Finally, .map() converts undefined to the key value. So, literally, using .fill(1) or .fill(129102910450) is really the same, the result will always be an array of 10 elements with values from 0 to 9. Conclusion: the error is somewhere else as already mentioned by @GünterZöchbauer, nothing else to say here but the fact that the ngFor loop is wrong.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.