Vscode-ng-language-service: index value is not number error in template

Created on 27 Nov 2019  路  5Comments  路  Source: angular/vscode-ng-language-service

Describe the bug

Showing error for index value from ngFor is not numeric value.

(variable) i
Expected a numeric typeng(0)

To Reproduce

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Logs

Please attach two logs:

  1. Console output (Go to toolbar --> View --> Output, and copy the contents)
  2. Log file (Path is printed to the console output at startup)

Screenshots

If applicable, add screenshots to help explain your problem.

image

Additional context

Add any other context about the problem here.

bug

Most helpful comment

in my case it is saying:

Expected a number type ng(0)

for following code

<div *ngFor="let file of files; let i = index;">
   <p>File #{{i+1}}: {{file.name}}</p>
</div>
....

All 5 comments

I getting same kind of error for the *ngIf check. I didn't get this before
Capturess

I am getting the same error when interpolating the index variable from an ngFor and trying to add a number to it. For example:

<ng-container *ngFor="let item of items; index as i">

{{i + 1}} <-- Error

</ng-container>

I have noticed that if the keyvalue pipe is used in the ngFor declaration, the error does not appear. For example:

<ng-container *ngFor="let item of items | keyvalue; index as i">

{{i + 1}} <-- No Error

</ng-container>

Same error here and somehow this ist new after a VS Code update and maybe an update of "Angular Language Service". I was wondering because this was old code which now throws this error, but serves and builds fine.

<div *ngFor="let product of productItems; let i = index">
      <div *ngIf="i % 3 === 0 " class="card-deck mt-2">
        <div class="card" *ngFor="let item of productItems.slice(i,i+3)">
...

The variable "i" in lines 2 and 3 are marked as an error "Expected a numeric type ng(0)".

in my case it is saying:

Expected a number type ng(0)

for following code

<div *ngFor="let file of files; let i = index;">
   <p>File #{{i+1}}: {{file.name}}</p>
</div>
....

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings