【发布时间】:2017-01-11 21:16:48
【问题描述】:
我需要在AngularJS HTML select标签中设置一个$scope的对象,我会解释清楚我的要求:
这是我的 angularjs 脚本代码:
$scope.departments = $http.get("getDepartmentList");
在部门范围内,我将从从数据库中获取的 spring mvc 控制器获取部门对象列表。
我将在 html select as 中使用的部门范围
<select name="department"
ng-model="department"
class="form-control"
ng-options="department as department.deptName for department in departments"
class="select_form" >
option
value="">Select Department</option>
</select>
创建时,我可以在从选择列表中选择后获取部门对象。在修改过程中,我将有一个部门对象需要在选择列表中设置和选择,但它没有被选中,仅列出对象列表,而在修改过程中没有选择修改的对象。
在修改期间我将部门范围设置为
$scope.department = $http.get("getDepartmentById);
所以上面的代码将在范围内有一个部门对象,但它没有在列表中选择
我尝试在选择标签中使用 ng-value 作为
<select name="department"
ng-model="department"
class="form-control"
ng-options="department as department.deptName for department in departments"
ng-value="department"
class="select_form" >
<option value="">Select Department</option>
</select>
但是没有用,任何人都可以帮助从 html 页面中的选择列表中设置对象。
【问题讨论】:
标签: angularjs select angularjs-scope