我在 Angular 2 应用程序(测试版 1)中有一个 ComponentB。在我将它放在 ComponentA 的 ngFor 循环中之前,它工作得非常好。我收到了相当神秘的错误:
例外: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 原始异常:TypeError: viewFactory_ComponentB0 不是函数BrowserDomAdapter.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 原始堆栈跟踪: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$promise$asap$$flush @ angular2-polyfills.js:1305 angular2.dev.js:22690 TypeError: viewFactory_ComponentB0 不是 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)
组分A:
@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 {}
任何提示/帮助高度赞赏。