【发布时间】:2018-02-16 23:10:00
【问题描述】:
我以前在我的 Angular 4 应用程序中使用过 lodash,只需将其导入并使用它,如下所示:
import lodash from 'lodash';
public getSubtotal() : number {
return lodash.sumBy(this.cartItems, function(item) {
return item.product.price * item.item.quantity;
})
}
我再次尝试类似地使用 lodash,但收到一个错误,即 lodash 未定义。
import lodash from 'lodash';
lodash.indexOf([1, 2, 1, 2], 2);
我收到以下错误:
ERROR TypeError: Cannot read property 'indexOf' of undefined
at CustomizeComponent.showTopping (customize.component.ts:39)
at Object.eval [as updateDirectives] (CustomizeComponent.html:285)
at Object.debugUpdateDirectives [as updateDirectives] (core.js:14638)
at checkAndUpdateView (core.js:13785)
at callViewAction (core.js:14136)
at execComponentViewsAction (core.js:14068)
at checkAndUpdateView (core.js:13791)
at callViewAction (core.js:14136)
at execEmbeddedViewsAction (core.js:14094)
at checkAndUpdateView (core.js:13786)
【问题讨论】: