Angular2:将<select>组合框绑定到从ngOnInit()中的API检索到的对象列表时,运行时错误

用户名

我正在忙于angular2 Web应用程序,我有一个选择html组合框,我正尝试将其绑定到一系列Active Stock Take对象。我的应用程序似乎可以编译,没有任何问题,但是出现以下运行时错误。知道这意味着什么吗?我会以错误的方式处理吗?使用可以安全导航吗?

我的错误:

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:

<select class="form-control" [(ngModel)]="activeStockTakes?">
    <option *ngFor="let activeStockTake of activeStockTakes" [ngValue]="activeStockTake">{{activeStockTake.UserCode}} - {{activeStockTake.Comment}}
    </option>
</select>

我的stock-takeComponent.ts的ngOninit:

this.restService.getActiveStockTakes()
  .subscribe(
   res => {
    this.activeStockTakes = res;
    console.log(this.activeStockTakes);
   },
   res => {
    console.log(res);
   }
  );
}
贡特·佐赫鲍尔(GünterZöchbauer)

?在结尾处有多余[(ngModel)]="activeStockTakes?"

的绑定ngModel不能是用于生成<option>元素的数组

[(ngModel)]="activeStockTakes"

应该是这样的

[(ngModel)]="selectedActiveStockTakes"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将Select2集成到Angular2应用中

Angular 2形式:将html select绑定到对象集合

Angular2 - 使用 Select2 多选时绑定到 formControl

将bootstrap模块和ng2-select模块集成到angular2 5min快速入门

使用Angular2将动态对象绑定到HTML

angular2将事件绑定到可观察对象

将方法绑定到对象运行时后期绑定

Angular2在运行时将AppModule的服务注入到依赖的NgModule的组件中吗?

如何在MVC视图中使用jquery将数据绑定到组合框运行时?

angular2将模型值绑定到单选按钮

Angular2。将数据从指令绑定到模板

Angular2 将值绑定到结构指令

Angular2,TypeScript,如何将属性值读取/绑定到组件类(在ngOnInit中未定义)

使用双向绑定将<select>中的Angular2 <option>默认

模型绑定不适用于angular2中的select

Angular2 [ngClass]-将直接绑定与条件类组合

如何使“根据输入字符串上的获取api调用获取的数据根据检索到的数据显示动态选项列表的搜索框”(如amp邮件中的select2)

如何从此 JSON 读取数据并将其绑定到 Angular 2+ 中的 Select 下拉列表

Angular2:集成ng2-select时遇到麻烦

运行时将组件或模块加载到angular2的模块中

访问angular2中的Select元素值会给出错误

将范围值绑定到angular的ui-select中的ui-select-match属性

将列表从类绑定到组合框

将数据传递到样式组件angular2

Angular2:将数据传递到子组件

将环境变量传递到angular2库

如何将Swiftmailer集成到Angular2

Angular2:将价值从组件传递到服务

将注销的用户重定向到以 angular2 登录