0
私はangular2 Webアプリケーションで忙しいです、私はバインドしようとしている選択したhtmlコンボボックスを持っていますアクティブストックの配列はオブジェクトを取る。私のアプリは何の問題もなくコンパイルするようですが、私は次のランタイムエラーが発生します。これがどういう意味か?私はこれについて間違った方法をとっていますか?安全なナビゲーションでこれを行うことは可能ですか?Angular2:ngOnInit()のAPIから取得したオブジェクトのリストに<select>コンボボックスをバインドするときのランタイムエラー
マイエラー:
zone.js:420
Unhandled Promise rejection:Cannot set property 'stack' of undefined; Zone:<root>; Task:Promise.then; Value:TypeError: Cannot set property 'stack' of undefined
at SyntaxError.set [as stack] (
http://localhost:4200/vendor.bundle.js:75980:61)
at assignAll (
http://localhost:4200/vendor.bundle.js:111629:29)
at SyntaxError.ZoneAwareError (
http://localhost:4200/vendor.bundle.js:111700:16)
at SyntaxError.BaseError [as constructor] (
http://localhost:4200/vendor.bundle.js:75942:16)
at new SyntaxError (
http://localhost:4200/vendor.bundle.js:6861:16)
at TemplateParser.parse (
http://localhost:4200/vendor.bundle.js:21436:19)
at JitCompiler._compileTemplate (
http://localhost:4200/vendor.bundle.js:55485:68)
at
http://localhost:4200/vendor.bundle.js:55368:62
at Set.forEach (native)
at JitCompiler._compileComponents (
http://localhost:4200/vendor.bundle.js:55368:19)
at createResult (
http://localhost:4200/vendor.bundle.js:55251:19)
at ZoneDelegate.invoke (
http://localhost:4200/vendor.bundle.js:111167:26)
at Zone.run (
http://localhost:4200/vendor.bundle.js:111038:43)
at
http://localhost:4200/vendor.bundle.js:111460:57
at ZoneDelegate.invokeTask (
http://localhost:4200/vendor.bundle.js:111200:35)
TypeError: Cannot set property 'stack' of undefined
at SyntaxError.set [as stack] (
http://localhost:4200/vendor.bundle.js:75980:61)
at assignAll (
http://localhost:4200/vendor.bundle.js:111629:29)
at SyntaxError.ZoneAwareError (
http://localhost:4200/vendor.bundle.js:111700:16)
at SyntaxError.BaseError [as constructor] (
http://localhost:4200/vendor.bundle.js:75942:16)
at new SyntaxError (
http://localhost:4200/vendor.bundle.js:6861:16)
at TemplateParser.parse (
http://localhost:4200/vendor.bundle.js:21436:19)
at JitCompiler._compileTemplate (
http://localhost:4200/vendor.bundle.js:55485:68)
at
http://localhost:4200/vendor.bundle.js:55368:62
at Set.forEach (native)
at JitCompiler._compileComponents (
http://localhost:4200/vendor.bundle.js:55368:19)
at createResult (
http://localhost:4200/vendor.bundle.js:55251:19)
at ZoneDelegate.invoke (
http://localhost:4200/vendor.bundle.js:111167:26)
at Zone.run (
http://localhost:4200/vendor.bundle.js:111038:43)
at
http://localhost:4200/vendor.bundle.js:111460:57
at ZoneDelegate.invokeTask (
http://localhost:4200/vendor.bundle.js:111200:35)
zone.js:422
list of 1 items
aaZoneAwareError{stack: "Error: Uncaught (in promise): TypeError: Cannot se…calhost:4200/vendor.bundle.js:111358:35) [<root>]", message: "Uncaught (in
promise): TypeError: Cannot set prope…http://localhost:4200/vendor.bundle.js:111200:35)", originalStack: "Error: Uncaught (in promise): TypeError: Cannot
se…http://localhost:4200/vendor.bundle.js:111358:35)", zoneAwareStack: "Error: Uncaught (in promise): TypeError: Cannot se…calhost:4200/vendor.bundl
私のhtml:私の株式takeComponent.tsの
<select class="form-control" [(ngModel)]="activeStockTakes?">
<option *ngFor="let activeStockTake of activeStockTakes" [ngValue]="activeStockTake">{{activeStockTake.UserCode}} - {{activeStockTake.Comment}}
</option>
</select>
マイngOninit:
this.restService.getActiveStockTakes()
.subscribe(
res => {
this.activeStockTakes = res;
console.log(this.activeStockTakes);
},
res => {
console.log(res);
}
);
}
のようなものバインドする必要があります
<option>
要素を生成するために使用する配列にすることはできませんngModel
への結合[(ngModel)]配列は、本当に奇妙なように、あなたを'selectedStock'のような変数にバインドする必要があります。 また、コンポーネントのコンストラクタ内の空の配列にactiveStockTagesを初期化する必要があります。 – Melou@Melouコンストラクタ内のAPIからオープンストックテイクのリストを受け取るので、ngModelをバインドする必要があります。 selectedStockTakeを使用して、ストックタグの配列にオプションタグのngForを使用して、コンボボックスに値を入力しますか? – user2094257
はい、それは考えです。 – Melou