里面ngFor Angular2组件抛出错误(的ViewFactory不是函数) [英] Angular2 Component inside ngFor throws Error (viewFactory is not a function)

查看:174
本文介绍了里面ngFor Angular2组件抛出错误(的ViewFactory不是函数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以componentB在角2的应用程序(测试版1)。直到我把它放在一个ComponentA循环ngFor里面工作完全正常。我收到的,而神秘的错误:

I have a a ComponentB in a Angular 2 app (beta 1). It works perfectly fine until I place it inside a ngFor loop in ComponentA. I receive the rather cryptic error of:

例外:类型错误: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 @接收。 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 $承诺尽快$ $$平齐@ angular2-polyfills.js:1305
  angular2.dev.js:22690原始异常:类型错误: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 @接收。 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 $ $答应尽快$$平齐@ angular2-polyfills.js:1305
  angular2.dev.js:22690 ORIGINAL堆栈跟踪:BrowserDomAdapter.logError @ angular2.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(匿名函数)@ angular2.dev.js:13140run @ angular2-polyfills.js:138NgZone._notifyOnTurnDone @ angular2.dev.js:13139(匿名函数)@ angular2.dev.js:13254zoneBoundFn @ angular2-polyfills.js:111lib $ ES6 $承诺尽快$ $$平齐@ angular2-polyfills.js:1305
  angular2.dev.js:22690类型错误:viewFactory_ComponentB0不是一个函数
      在AppElement.viewFactory_ComponentA1 [如embeddedViewFactory(viewFactory_ComponentA:388)
      在AppViewManager_.createEmbeddedViewInContainer(angular2.dev.js:9185)
      在ViewContainerRef_.createEmbeddedView(angular2.dev.js:5890)
      在NgFor._bulkInsert(angular2.dev.js:14608)
      在NgFor._applyChanges(angular2.dev.js:14567)
      在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)

EXCEPTION: TypeError: viewFactory_ComponentB0 is not a function in [numbers in ComponentA@1:23]BrowserDomAdapter.logError @ angular2.dev.js:22690BrowserDomAdapter.logGroup @ angular2.dev.js:22701ExceptionHandler.call @ angular2.dev.js:1163(anonymous function) @ angular2.dev.js:12416NgZone._notifyOnError @ angular2.dev.js:13324collection_1.StringMapWrapper.merge.onError @ angular2.dev.js:13228run @ angular2-polyfills.js:141(anonymous function) @ angular2.dev.js:13247NgZone.run @ angular2.dev.js:13209(anonymous function) @ 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(anonymous function) @ 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 is not a functionBrowserDomAdapter.logError @ angular2.dev.js:22690ExceptionHandler.call @ angular2.dev.js:1172(anonymous function) @ angular2.dev.js:12416NgZone._notifyOnError @ angular2.dev.js:13324collection_1.StringMapWrapper.merge.onError @ angular2.dev.js:13228run @ angular2-polyfills.js:141(anonymous function) @ angular2.dev.js:13247NgZone.run @ angular2.dev.js:13209(anonymous function) @ 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(anonymous function) @ angular2.dev.js:13254zoneBoundFn @ angular2-polyfills.js:111lib$es6$promise$asap$$flush @ angular2-polyfills.js:1305 angular2.dev.js:22690 ORIGINAL STACKTRACE:BrowserDomAdapter.logError @ angular2.dev.js:22690ExceptionHandler.call @ angular2.dev.js:1175(anonymous function) @ angular2.dev.js:12416NgZone._notifyOnError @ angular2.dev.js:13324collection_1.StringMapWrapper.merge.onError @ angular2.dev.js:13228run @ angular2-polyfills.js:141(anonymous function) @ angular2.dev.js:13247NgZone.run @ angular2.dev.js:13209(anonymous function) @ 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(anonymous function) @ angular2.dev.js:13254zoneBoundFn @ angular2-polyfills.js:111lib$es6$promise$asap$$flush @ angular2-polyfills.js:1305 angular2.dev.js:22690 TypeError: viewFactory_ComponentB0 is not a function at AppElement.viewFactory_ComponentA1 [as embeddedViewFactory] (viewFactory_ComponentA:388) at AppViewManager_.createEmbeddedViewInContainer (angular2.dev.js:9185) at ViewContainerRef_.createEmbeddedView (angular2.dev.js:5890) at NgFor._bulkInsert (angular2.dev.js:14608) at NgFor._applyChanges (angular2.dev.js:14567) at NgFor.ngDoCheck (angular2.dev.js:14552) at AbstractChangeDetector.ChangeDetector_ComponentA_0.detectChangesInRecordsInternal (viewFactory_ComponentA:45) at AbstractChangeDetector.detectChangesInRecords (angular2.dev.js:7825) at AbstractChangeDetector.runDetectChanges (angular2.dev.js:7808) at AbstractChangeDetector._detectChangesInViewChildren (angular2.dev.js:7892)

ComponentA:

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 {}

任何提示/帮助高AP preciated。

Any hints/help highly appreciated.

推荐答案

作为建议的@TylerDurden

As suggested by @TylerDurden

此错误消息是由周期检测引入一个bug产生的(见#6404 )。

This error message is produced by a bug introduced in cycle detection (see #6404).

还有已经处于主修复(见#6474 )尚未公布。这将肯定是beta.2。

There's already a fix in master (see #6474) not yet released. This will for sure be in beta.2.

的建议是降级到beta.0直到风暴结束。

The recommendation is to downgrade to beta.0 until the storm is over.

此问题已得到修复在beta.2(有微小的问题仍然存在)。请参见的changelog 了解更多详情。

This issue has been fixed in beta.2 (issues with minification are still there). See changelog for more details.

这篇关于里面ngFor Angular2组件抛出错误(的ViewFactory不是函数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆