简体   繁体   English

角度Ng选项错误?

[英]angular Ng-options error?

I am trying to use an ng-option based drop down. 我正在尝试使用基于ng-option的下拉菜单。 My code currently looks like this: 我的代码目前看起来像这样:

<select
     ng-options="choice.id as choice.singular in model.quanityChoices"
     ng-model="med.id"
     <option value=""></option>
</select>

The model data this is based off looks like this: 基于此的模型数据如下所示:

[
 {id: 1, singular: 'word'},
 {id: 2, singular: 'word2'}
]

Currently my goal is to have a dropdown where the user will see the options 'word' and 'words' but the value that gets applied is the ID. 目前我的目标是有一个下拉列表,用户将看到选项'word'和'words',但应用的值是ID。

Currently my code has the following error: 目前我的代码有以下错误:

Error: [ngOptions:iexp] Expected expression in form of '_select_ (as _label_)? for (_key_,)?_value_ in _collection_' but got 'choice.id as choice.singular in model.quantityFormChoices'. Element: <select...

You didn't structure it correctly, look at the error as it gives you the details on how to do it: 您没有正确构造它,查看错误,因为它为您提供了有关如何执行此操作的详细信息:

<select
     ng-options="choice.id as choice.singular for choice in model.quanityChoices"
     ng-model="med.id"
     <option value=""></option>
</select>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM