问题原因是在Angular 7中找不到underscore模块。下面是解决该问题的步骤:
首先,确保已经安装了underscore模块。可以运行以下命令来安装underscore模块:
npm install underscore --save
在Angular项目的根目录下找到tsconfig.json文件,然后添加以下内容:
"compilerOptions": {
"paths": {
"underscore": [
"node_modules/underscore/underscore.d.ts"
]
}
}
在Angular项目中使用underscore模块的组件或服务中,导入underscore并使用它。例如:
import * as _ from 'underscore';
// 使用underscore
_.each([1, 2, 3], function(num) {
console.log(num);
});
重新启动Angular开发服务器并构建项目:
ng serve
这样就可以解决Angular 7中找不到underscore模块的问题了。