Angular 2 / Angular 2 CLI / lodash 函数未找到
Angular 2 / Angular 2 CLI / lodash functions not found
angular-cli beta 18
出现错误
Error: Uncaught (in promise): TypeError: __WEBPACK_IMPORTED_MODULE_6_lodash__.find is not a function
Lodash + 类型已添加到 package.json:-
"lodash": "4.14",
"@types/lodash": "4.14.38",
在 angular-cli.json 的脚本部分,我们引用了模块
"../node_modules/lodash/lodash.js",
我们正在导入 lodash 使用:-
import * as _ from 'lodash';
编译的 scripts.bundle.js
包含 lodash javascript。
有什么我忘了的吗?
谢谢!
编辑:
不要添加到您的 angular-cli.json 文件脚本部分。这不需要!
你似乎就在那里,只是为了确保,这里是我如何在我的一个项目中重现它的步骤:
- 停止当前
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
再
angular-cli beta 18
出现错误Error: Uncaught (in promise): TypeError: __WEBPACK_IMPORTED_MODULE_6_lodash__.find is not a function
Lodash + 类型已添加到 package.json:-
"lodash": "4.14",
"@types/lodash": "4.14.38",
在 angular-cli.json 的脚本部分,我们引用了模块
"../node_modules/lodash/lodash.js",
我们正在导入 lodash 使用:-
import * as _ from 'lodash';
编译的 scripts.bundle.js
包含 lodash javascript。
有什么我忘了的吗?
谢谢!
编辑: 不要添加到您的 angular-cli.json 文件脚本部分。这不需要!
你似乎就在那里,只是为了确保,这里是我如何在我的一个项目中重现它的步骤:
- 停止当前
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
再