找不到Angular 2/Angular 2 CLI/lodash函数 [英] Angular 2 / Angular 2 CLI / lodash functions not found
问题描述
我们收到有关angular-cli beta 18的错误
We are getting the error with angular-cli beta 18
Error: Uncaught (in promise): TypeError: __WEBPACK_IMPORTED_MODULE_6_lodash__.find is not a function
Lodash +类型已添加到package.json:-
Lodash + Types were added to the package.json: -
"lodash": "4.14",
"@types/lodash": "4.14.38",
在angular-cli.json的脚本部分中,我们对模块进行了引用
In the scripts section of angular-cli.json we have a reference to the module
"../node_modules/lodash/lodash.js",
我们正在使用以下方法导入lodash:-
We are importing lodash using: -
import * as _ from 'lodash';
已编译的scripts.bundle.js
包含lodash javascript.
The compiled scripts.bundle.js
has the lodash javascript included.
有什么我忘记的东西吗?
Is there anything I have forgotten about?
谢谢!
推荐答案
编辑: 请勿添加到您的angular-cli.json文件脚本部分.不需要!
您似乎已经准备好了,只是为了确保,这是我如何在我的一个项目中进行复制的步骤:
You seem to have it right there, just to make sure, here are the steps with how i can reproduce it working on one of my projects:
- 停止当前的
ng serve
- 执行
npm install lodash --save
和npm install @types/lodash --save-dev
- 在控制器中执行
import * as _ from 'lodash';
- 像这样使用它:
console.log(_.chunk(['a', 'b', 'c', 'd'], 2));
再次 -
ng serve
- stop the current
ng serve
- do
npm install lodash --save
andnpm install @types/lodash --save-dev
- In the controler do your
import * as _ from 'lodash';
- Use it like this:
console.log(_.chunk(['a', 'b', 'c', 'd'], 2));
ng serve
again
这篇关于找不到Angular 2/Angular 2 CLI/lodash函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!