Angular:使用ngFor的索引会引发错误,期望数值类型

问题描述 投票:0回答:1

在最新的Visual Studio Code更新之后,我在Angular 8应用程序中写了很久以前的代码时遇到错误。

<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)">
...

第2行和第3行中的变量“ i”被标记为错误“期望数字类型ng(0)”。

目前我有点头绪,因为代码按预期工作,并且“ ng serve”和“ ng build”成功地服务和构建。

angular typescript
1个回答
0
投票

如果您使用的是语言服务,则可能会出现错误。有一个类似的现象问题。

© www.soinside.com 2019 - 2024. All rights reserved.