Angular Lodash forEach不是函数-更新后

Angular Lodash forEach不是函数-更新后,angular,lodash,angular-cli,Angular,Lodash,Angular Cli,我一直在Angular CLI 2.2.3中使用Lodash,没有任何问题。但是,在将Angular CLI更新到2.3.1之后,我遇到了一些问题。第一个错误是错误:在angular cli?中找不到模块“lodash”?。 我通过以下方式解决了此问题: npm install lodash --save npm install @types/lodash --save-dev 并添加到angular-cli.json "scripts": ["../node_modules/lodash/l

我一直在Angular CLI 2.2.3中使用Lodash,没有任何问题。但是,在将Angular CLI更新到2.3.1之后,我遇到了一些问题。第一个错误是错误:在angular cli?中找不到模块“lodash”?。 我通过以下方式解决了此问题:

npm install lodash --save
npm install @types/lodash --save-dev
并添加到angular-cli.json

"scripts": ["../node_modules/lodash/lodash.js”],
这使得MyAngular 2项目可以无错误地编译。但是,当我转到使用lodash foreach的组件时,会出现以下错误:

EXCEPTION: Error in ./FormDetailComponent class FormDetailComponent - inline template:5:73 caused by: __WEBPACK_IMPORTED_MODULE_10_lodash__.forEach is not a function
ErrorHandler.handleError @ error_handler.js:50
next @ application_ref.js:346
schedulerFn @ async.js:91
SafeSubscriber.__tryOrUnsub @ Subscriber.js:223
SafeSubscriber.next @ Subscriber.js:172
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ async.js:77
NgZone.triggerError @ ng_zone.js:329
onHandleError @ ng_zone.js:290
ZoneDelegate.handleError @ zone.js:246
Zone.runTask @ zone.js:154
ZoneTask.invoke @ zone.js:345
error_handler.js:52 ORIGINAL EXCEPTION: __WEBPACK_IMPORTED_MODULE_10_lodash__.forEach is not a function
ErrorHandler.handleError @ error_handler.js:52
next @ application_ref.js:346
schedulerFn @ async.js:91
SafeSubscriber.__tryOrUnsub @ Subscriber.js:223
SafeSubscriber.next @ Subscriber.js:172
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ async.js:77
NgZone.triggerError @ ng_zone.js:329
onHandleError @ ng_zone.js:290
ZoneDelegate.handleError @ zone.js:246
Zone.runTask @ zone.js:154
ZoneTask.invoke @ zone.js:345
error_handler.js:55 ORIGINAL STACKTRACE:
ErrorHandler.handleError @ error_handler.js:55
next @ application_ref.js:346
schedulerFn @ async.js:91
SafeSubscriber.__tryOrUnsub @ Subscriber.js:223
SafeSubscriber.next @ Subscriber.js:172
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ async.js:77
NgZone.triggerError @ ng_zone.js:329
onHandleError @ ng_zone.js:290
ZoneDelegate.handleError @ zone.js:246
Zone.runTask @ zone.js:154
ZoneTask.invoke @ zone.js:345
error_handler.js:56 TypeError: __WEBPACK_IMPORTED_MODULE_10_lodash__.forEach is not a function
    at FormTableComponent.setTotalFlex (form-table.component.ts:92)
    at FormTableComponent.ngOnInit (form-table.component.ts:64)
    at Wrapper_FormTableComponent.ngDoCheck (wrapper.ngfactory.js:54)
    at View_FormDetailComponent3.detectChangesInternal (component.ngfactory.js:126)
    at View_FormDetailComponent3.AppView.detectChanges (view.js:425)
    at View_FormDetailComponent3.DebugAppView.detectChanges (view.js:620)
    at ViewContainer.detectChangesInNestedViews (view_container.js:67)
    at View_FormDetailComponent1.detectChangesInternal (component.ngfactory.js:261)
    at View_FormDetailComponent1.AppView.detectChanges (view.js:425)
    at View_FormDetailComponent1.DebugAppView.detectChanges (view.js:620)
    at ViewContainer.detectChangesInNestedViews (view_container.js:67)
    at CompiledTemplate.proxyViewClass.View_FormDetailComponent0.detectChangesInternal (component.ngfactory.js:326)
    at CompiledTemplate.proxyViewClass.AppView.detectChanges (view.js:425)
    at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (view.js:620)
    at CompiledTemplate.proxyViewClass.AppView.internalDetectChanges (view.js:410)
ErrorHandler.handleError @ error_handler.js:56
next @ application_ref.js:346
schedulerFn @ async.js:91
SafeSubscriber.__tryOrUnsub @ Subscriber.js:223
SafeSubscriber.next @ Subscriber.js:172
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ async.js:77
NgZone.triggerError @ ng_zone.js:329
onHandleError @ ng_zone.js:290
ZoneDelegate.handleError @ zone.js:246
Zone.runTask @ zone.js:154
ZoneTask.invoke @ zone.js:345
error_handler.js:59 ERROR CONTEXT:
ErrorHandler.handleError @ error_handler.js:59
next @ application_ref.js:346
schedulerFn @ async.js:91
SafeSubscriber.__tryOrUnsub @ Subscriber.js:223
SafeSubscriber.next @ Subscriber.js:172
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ async.js:77
NgZone.triggerError @ ng_zone.js:329
onHandleError @ ng_zone.js:290
ZoneDelegate.handleError @ zone.js:246
Zone.runTask @ zone.js:154
ZoneTask.invoke @ zone.js:345
error_handler.js:60 DebugContext {_view: View_FormDetailComponent3, _nodeIndex: 4, _tplRow: 5, _tplCol: 73}
ErrorHandler.handleError @ error_handler.js:60
next @ application_ref.js:346
schedulerFn @ async.js:91
SafeSubscriber.__tryOrUnsub @ Subscriber.js:223
SafeSubscriber.next @ Subscriber.js:172
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ async.js:77
NgZone.triggerError @ ng_zone.js:329
onHandleError @ ng_zone.js:290
ZoneDelegate.handleError @ zone.js:246
Zone.runTask @ zone.js:154
ZoneTask.invoke @ zone.js:345
Subscriber.js:227 Uncaught ViewWrappedError {_nativeError: Error: Error in ./FormDetailComponent class FormDetailComponent - inline template:5:73 caused by: __…, originalError: TypeError: __WEBPACK_IMPORTED_MODULE_10_lodash__.forEach is not a function
    at FormTableComponent…, context: DebugContext}
我正在将lodash函数导入到我的组件中,如下所示:

import * as _ from "lodash"; 
下面是我在代码中使用foreach的方式:

printYArr(): void {
    this.totalFlex  = [];
    // Get y
    let yArr: number[] = [];
    // Get array of y
    _.forEach(this.elements, function(obj: FormElement) {
      if (yArr.indexOf(obj.y) < 0) {
        yArr.push(obj.y);
      }
    });
    console.log('yarr',yArr);
  }

还有谁遇到这个问题,能帮我解决吗?提前感谢

您是否尝试过使用u.each而不是u.forEach?您是否会遇到相同类型的错误?顺便说一句,我从来没有过这个问题。这是暗中刺伤;这不应该奏效,但值得一试。
"@angular/common": "^2.3.1",
    "@angular/compiler": "^2.3.1",
    "@angular/core": "^2.3.1",
    "@angular/flex-layout": "^2.0.0-beta.1",
    "@angular/forms": "^2.3.1",
    "@angular/http": "^2.3.1",
    "@angular/material": "^2.0.0-beta.1",
    "@angular/platform-browser": "^2.3.1",
    "@angular/platform-browser-dynamic": "^2.3.1",
    "@angular/router": "^3.3.1",
    "angular2-jwt": "^0.1.28",
    "angular2-uuid": "^1.1.0",
    "core-js": "^2.4.1",
    "lodash": "^4.17.4",
    "rxjs": "^5.0.1",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.7.4"