ngFor中的Angular2组件抛出错误(viewFactory不是函数)

Tyl*_*den 5 javascript angular2-template angular

我在Angular 2 app(beta 1)中有一个ComponentB.它完全正常,直到我将它放在ComponentA中的ngFor循环中.我收到了相当神秘的错误:

EXCEPTION:TypeError:viewFactory_ComponentB0不是[ComponentA @ 1:23中的数字]中的函数BrowserDomAdapter.logError @ angular2.dev.js:22690BrowserDomAdapter.logGroup @ angular2.dev.js:22701ExceptionHandler.call @ angular2.dev.js:1163 (匿名函数)@ angular2.dev.js:12416NgZone._notifyOnError @ angular2.dev.js:13324collection_1.StringMapWrapper.merge.onError @ angular2.dev.js:13228run @ angular2-polyfills.js:141(匿名函数)@ angular2 .dev.js:13247NgZone.run @ angular2.dev.js:13209(匿名函数)@ angular2.dev.js:12499schedulerFn @ angular2.dev.js:12742tryCatcher @ Rx.js:31Subscriber.next @ Rx.js:9500Subject ._next @ Rx.js:9999Subject.next @ Rx.js:9963EventEmitter.emit @ angular2.dev.js:12723(匿名函数)@ angular2.dev.js:13140run @ angular2-polyfills.js:138NgZone._notifyOnTurnDone @ angular2 .dev.js:13139(匿名函数)@ angular2.dev.js:13254zoneBoundFn @ angular2-polyfills.js:111lib $ es6 $ promise $ asap $$ flush @ angular2-polyfills.js:1305 angular2.dev.js:22690 ORIGINAL EXCEPTION:TypeError:viewFactory_ComponentB0不是functionBrowserDomAdapter.logError @ angular2.dev.js:22690ExceptionHandler.call @ angular2.dev.js:1172(匿名函数)@ angular2.dev.js:12416NgZone._notifyOnError @ angular2. dev.js:13324collection_1.StringMapWrapper.merge.onError @ angular2.dev.js:13228run @ angular2-polyfills.js:141(匿名函数)@ angular2.dev.js:13247NgZone.run @ angular2.dev.js:13209(匿名函数)@ angular2.dev.js:12499schedulerFn @ angular2.dev.js:12742tryCatcher @ Rx.js:31Subscriber.next @ Rx.js:9500Subject._next @ Rx.js:9999Subject.next @ Rx.js:9963EventEmitter. emit @ angular2.dev.js:12723(匿名函数)@ angular2.dev.js:13140run @ angular2-polyfills.js:138NgZone._notifyOnTurnDone @ angular2.dev.js:13139(匿名函数)@ angular2.dev.js: 13254zoneBoundFn @ angular2-polyfills.js:111lib $ es6 $ promise $ asap $$ flush @ angular2-polyfills.js:1305 angular2.dev.js:22690 ORIGINAL STACKTRACE:BrowserDomAdapter.logError @ angula r2.dev.js:22690ExceptionHandler.call @ angular2.dev.js:1175(匿名函数)@ angular2.dev.js:12416NgZone._notifyOnError @ angular2.dev.js:13324collection_1.StringMapWrapper.merge.onError @ angular2.dev. js:13228run @ angular2-polyfills.js:141(匿名函数)@ angular2.dev.js:13247NgZone.run @ angular2.dev.js:13209(匿名函数)@ angular2.dev.js:12499schedulerFn @ angular2.dev. js:12742tryCatcher @ Rx.js:31Subscriber.next @ Rx.js:9500Subject._next @ Rx.js:9999Subject.next @ Rx.js:9963EventEmitter.emit @ angular2.dev.js:12723(anonymous function)@ angular2. dev.js:13140run @ angular2-polyfills.js:138NgZone._notifyOnTurnDone @ angular2.dev.js:13139(匿名函数)@ angular2.dev.js:13254zoneBoundFn @ angular2-polyfills.js:111lib $ es6 $ promise $ asap $ $ flush @ angular2-polyfills.js:1305 angular2.dev.js:22690 TypeError:viewFactory_ComponentB0不是AppViewManager_.Compateory上的AppElement.viewFactory_ComponentA1 [as embeddedViewFactory](viewFactory_ComponentA:388)的函数 mbeddedViewInContainer(angular2.dev.js:9185)位于NgFor._applyChanges(angular2.dev.js:14567)的NgFor._bulkInsert(angular2.dev.js:14608)的ViewContainerRef_.createEmbeddedView(angular2.dev.js:5890)处NgFor.ngDoCheck(angular2.dev.js:14552)在AbstractChangeDetector.ChangeDetector_ComponentA_0.detectChangesInRecordsInternal(viewFactory_ComponentA:45)在AbstractChangeDetector.detectChangesInRecords(angular2.dev.js:7825)在AbstractChangeDetector.runDetectChanges(angular2.dev.js:7808)在AbstractChangeDetector._detectChangesInViewChildren(angular2.dev.js:7892)

ComponentA:

@Component({
  selector: 'component-a'
  , directives: [
    FORM_DIRECTIVES
    , ComponentB
  ]
  , template: `
    <!-- works --><component-b [(ngFormControl)]="_formControl"></component-b>
    <!-- fails --><component-b *ngFor="#number of numbers" [(ngFormControl)]="_formControls[number]"></component-b>
  `
})

export class ComponentA {}
Run Code Online (Sandbox Code Playgroud)

任何提示/帮助高度赞赏.

Eri*_*nez 6

正如@TylerDurden所说

此错误消息由循环检测中引入的错误产生(请参阅#6404).

已经有一个主人(见#6474)的修复程序尚未发布.这肯定会在beta.2.

建议降级到beta.0,直到暴风雨结束.

更新

此问题已在beta.2中修复(缩小问题仍然存在).有关详细信息,请参阅changelog.