2016-05-09 6 views
1

ng-optionベースのドロップダウンを使用しようとしています。私のコードは、現在、次のようになります。これはオフに基づいています角度Ngオプションのエラー?

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

モデルデータは、次のようになります。ユーザーはオプション「単語」を参照する場所

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

現在、私の目標は、ドロップダウンを持っていることですと 'words'が適用されますが、適用される値はIDです。

現在、私のコードは次のようなエラーがあります。

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... 

答えて

3

あなたはそれはあなたにそれを行う方法の詳細を与えるようなエラーを見て、それを正しく構築しませんでした:

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

ああわかりました。これは明らかでした。私はコード内の別のオプションと比較していましたが、「選択肢の中で」選択肢がないことに気付かなかったのです。 –

+0

喜んで助けてください:) –

+0

受け入れることを忘れないでください –