2016-01-17 10 views
5

私はAngular 2 app(beta 1)でComponentBを持っています。私がComponentAのngForループの中に置くまで、それは完璧に動作します。Angular2 Component inside ngFor throwsエラー(viewFactoryは関数ではありません)

EXCEPTION: TypeError: viewFactory_ComponentB0 is not a function in [numbers in [email protected]: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:

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

任意のヒント/ヘルプ高く評価私はかなりの不可解なエラーが発生します。このエラーメッセージは、周期検出に導入バグによって産生される@TylerDurden

によって示唆されるよう

+3

これはベータ1で導入されたバグです([#6404](https://github.com/angular/angular/issues/6404)参照)。既に修正済みです([#6474](https://github.com/angular/angular/pull/6474)参照)ので、次のリリースを待つ必要があります。これらのバグを避けたい。 –

+0

plnkrを提供しますか? – micronyks

+0

@EricMartinezが指摘したように私はbeta.0にダウングレードしました。 – TylerDurden

答えて

6

#6404を参照)。

マスターにはまだ修正がありません(#6474参照)。これは確かにベータ2になります。

ストームが終了するまで、ベータ0にダウングレードすることをお勧めします。

更新

は、この問題は、(縮小との問題が残っている)beta.2で修正されています。詳細はchangelogを参照してください。

+0

ありがとうございました。私は数時間の回避策を見つけ出そうとしていました。 –

1

この問題は本当に解決されていますか?私は "ベータ0"に取り組んでいましたが、次のコードは私のために働いていましたが、ファイルをベータ2で更新すると、この記事と同じ問題が残ります。これは私のコードです:

// rowIterator.component.ts 
import {Component,forwardRef} from 'angular2/core'; 
import {ColumIteratorComponent} from './columIterator.component'; 
import {ModuleIteratorComponent} from './moduleIterator.component'; 

@Component({ 
    selector: '[rowIterator]', 
    template: ` 
    <div *ngFor="#element of rowData"> 
     <div columIterator *ngIf="element.column" [ngClass]="element.class" [columData]="element.column"></div> 

     <div moduleIterator *ngIf="element.module" [ngClass]="element.class" [moduleData]="element.module"></div> 
    </div> 
    `, 
    inputs: ['rowData'], 
    directives: [forwardRef(function() { return ColumIteratorComponent; }),ModuleIteratorComponent] 
}) 
export class RowIteratorComponent { 
    // "rowData" is a ARRAYS 
} 

//columnIterator.components.ts 
import {Component,forwardRef} from 'angular2/core'; 
import {RowIteratorComponent} from './rowIterator.component'; 
import {ModuleIteratorComponent} from './moduleIterator.component'; 

@Component({ 
    selector: '[columIterator]', 
    template:` 
    <div *ngFor="#element of columData"> 
     <div rowIterator *ngIf="element.row" [ngClass]="element.class" [rowData]="element.row"></div> 

     <div moduleIterator *ngIf="element.module" [ngClass]="element.class" [moduleData]="element.module"></div> 
    </div> 
    `, 
    inputs: ['columData'], 
    directives: [forwardRef(function(){return RowIteratorComponent;}), ModuleIteratorComponent] 
}) 
export class ColumIteratorComponent{ 
    // "columData" is a ARRAY 
} 

私はベータ0のバージョンでループのために、それぞれforwardRef(function() {return RowIteratorComponent;}機能とforwardRef(function() {return ColumIteratorComponent;})を使用する必要がありますし、何の問題を持っていませんが、バージョン管理のベータ2で、次のエラーが表示されます。

EXCEPTION: TypeError: viewFactory_ColumIteratorComponent0 is not a function in [element.column in [email protected]:25] 
EXCEPTION: TypeError: viewFactory_ColumIteratorComponent0 is not a function in [element.column in [email protected]:25]BrowserDomAdapter.logError @ angular2.dev.js:22911BrowserDomAdapter.logGroup @ angular2.dev.js:22922ExceptionHandler.call @ angular2.dev.js:1182(anonymous function) @ angular2.dev.js:12562NgZone._notifyOnError @ angular2.dev.js:13485collection_1.StringMapWrapper.merge.onError @ angular2.dev.js:13389Zone.run @ angular2-polyfills.js:1247(anonymous function) @ angular2.dev.js:13408NgZone.run @ angular2.dev.js:13370(anonymous function) @ angular2.dev.js:12661schedulerFn @ angular2.dev.js:12904tryCatcher @ Rx.js:234Subscriber.next @ Rx.js:9703Subject._next @ Rx.js:10202Subject.next @ Rx.js:10166EventEmitter.emit @ angular2.dev.js:12885(anonymous function) @ angular2.dev.js:13301Zone.run @ angular2-polyfills.js:1243NgZone._notifyOnTurnDone @ angular2.dev.js:13300(anonymous function) @ angular2.dev.js:13415zoneBoundFn @ angular2-polyfills.js:1220lib$es6$promise$$internal$$tryCatch @ angular2-polyfills.js:468lib$es6$promise$$internal$$invokeCallback @ angular2-polyfills.js:480lib$es6$promise$$internal$$publish @ angular2-polyfills.js:451(anonymous function) @ angular2-polyfills.js:123Zone.run @ angular2-polyfills.js:1243zoneBoundFn @ angular2-polyfills.js:1220lib$es6$promise$asap$$flush @ angular2-polyfills.js:262 
angular2.dev.js:22911 ORIGINAL EXCEPTION: TypeError: viewFactory_ColumIteratorComponent0 is not a functionBrowserDomAdapter.logError @ angular2.dev.js:22911ExceptionHandler.call @ angular2.dev.js:1191(anonymous function) @ angular2.dev.js:12562NgZone._notifyOnError @ angular2.dev.js:13485collection_1.StringMapWrapper.merge.onError @ angular2.dev.js:13389Zone.run @ angular2-polyfills.js:1247(anonymous function) @ angular2.dev.js:13408NgZone.run @ angular2.dev.js:13370(anonymous function) @ angular2.dev.js:12661schedulerFn @ angular2.dev.js:12904tryCatcher @ Rx.js:234Subscriber.next @ Rx.js:9703Subject._next @ Rx.js:10202Subject.next @ Rx.js:10166EventEmitter.emit @ angular2.dev.js:12885(anonymous function) @ angular2.dev.js:13301Zone.run @ angular2-polyfills.js:1243NgZone._notifyOnTurnDone @ angular2.dev.js:13300(anonymous function) @ angular2.dev.js:13415zoneBoundFn @ angular2-polyfills.js:1220lib$es6$promise$$internal$$tryCatch @ angular2-polyfills.js:468lib$es6$promise$$internal$$invokeCallback @ angular2-polyfills.js:480lib$es6$promise$$internal$$publish @ angular2-polyfills.js:451(anonymous function) @ angular2-polyfills.js:123Zone.run @ angular2-polyfills.js:1243zoneBoundFn @ angular2-polyfills.js:1220lib$es6$promise$asap$$flush @ angular2-polyfills.js:262 
angular2.dev.js:22911 ORIGINAL STACKTRACE:BrowserDomAdapter.logError @ angular2.dev.js:22911ExceptionHandler.call @ angular2.dev.js:1194(anonymous function) @ angular2.dev.js:12562NgZone._notifyOnError @ angular2.dev.js:13485collection_1.StringMapWrapper.merge.onError @ angular2.dev.js:13389Zone.run @ angular2-polyfills.js:1247(anonymous function) @ angular2.dev.js:13408NgZone.run @ angular2.dev.js:13370(anonymous function) @ angular2.dev.js:12661schedulerFn @ angular2.dev.js:12904tryCatcher @ Rx.js:234Subscriber.next @ Rx.js:9703Subject._next @ Rx.js:10202Subject.next @ Rx.js:10166EventEmitter.emit @ angular2.dev.js:12885(anonymous function) @ angular2.dev.js:13301Zone.run @ angular2-polyfills.js:1243NgZone._notifyOnTurnDone @ angular2.dev.js:13300(anonymous function) @ angular2.dev.js:13415zoneBoundFn @ angular2-polyfills.js:1220lib$es6$promise$$internal$$tryCatch @ angular2-polyfills.js:468lib$es6$promise$$internal$$invokeCallback @ angular2-polyfills.js:480lib$es6$promise$$internal$$publish @ angular2-polyfills.js:451(anonymous function) @ angular2-polyfills.js:123Zone.run @ angular2-polyfills.js:1243zoneBoundFn @ angular2-polyfills.js:1220lib$es6$promise$asap$$flush @ angular2-polyfills.js:262 
angular2.dev.js:22911 TypeError: viewFactory_ColumIteratorComponent0 is not a function... 
関連する問題