如何解决找不到模块'@angular/router/src/utils/collection'或其对应的类型声明

时间:2021-03-02 13:14:28

标签: angular typescript

我如何解决错误:

src/app/metronic/orderByLocation/locationsByOneOrder/locationsByOneOrder.component.ts:7:25 - error TS2307: Cannot find module '@angular/router/src/utils/collection' or its corresponding type declarations.m

7 import { forEach } from '@angular/router/src/utils/collection';
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Error: src/app/metronic/orderByLocation/update-location/subpoena-options/subpoena-options.component.ts:5:25 - error TS2307: Cannot find module '@angular/router/src/utils/collection' or its corresponding type declarations.

5 import { forEach } from '@angular/router/src/utils/collection';
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Error: src/app/metronic/orderByLocation/update-location/update-location.component.ts:6:25 - error TS2307: Cannot find module '@angular/router/src/utils/collection' or its corresponding type declarations.

6 import { forEach } from '@angular/router/src/utils/collection';

1 个答案:

答案 0 :(得分:0)

'forEach' 是一个 Javascript / Typescript 方法,而不是一个角度导入。它是数组原型的成员,因此需要在要操作的数组上调用它。

  1. 删除导入并使用如下。

    this.data.foreach(元素 => { doNextTask(); });

如果您想作为键和索引循环,则如下所示。

this.data.forEach(function callback(value, index) {
   console.log(`${index}: ${value}`);
});