id as ng-model for select in angularjs

老子叫甜甜 提交于 2019-12-05 01:23:14

ng-options patterns can be confusing to get started with, as there are quite a bunch.

What you wrote right now means:

select     as     speciality.lookupName    for   speciality   in   specialityList
 ^-- the value to set to   ^-- what to display      ^-- iteree name  ^-- iterables

So the variables you have available in the expression are everythin you have defined on the scope, and the contextual specialty variable. When you select something it'll assign it to select, which is indeed undefined.

What you're looking for is

ng-options="speciality.lookupId as speciality.lookupName for speciality in specialityList"

This will set the value of what ng-model is pointing to to the contextual specialty's lookupId

You have to change the select key that refers to the value key specified in your ng-options. Since your value key is speciality then to bind user.lookupId to your ng-model with the currently selected option's lookupId, you have to change select to specialty.lookupId

So your select's ng-options should be:

<select ng-model="user.lookupId" ng-options="speciality.lookupId as speciality.lookupName for speciality in specialityList" ng-change="selectedSpecilaty()">
  <option value="">-- choose speciality --</option>
</select>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!