无法弄清楚如何使用此选择框绑定对象的属性。 plunker
<select ng-model="currentEmployee.FirstName" ng-options="employee.EmployeeId as employee.FirstName for employee in employees" ng-change="change(employee)">
<option value="">-- Select Employee</option>
</select>
<input type="text" ng-model="currentEmployee.LastName" />
$scope.change = function(employee) {
$scope.currentEmployee.FirstName = employee.FirstName;
$scope.currentEmployee.LastName = employee.LastName;
};
答案 0 :(得分:2)
对于这种情况,您不需要使用ng-change
。
将ng-model
设置为实际的员工对象,并将其绑定到$scope.currentEmployee
。
<select ng-model="currentEmployee"
ng-options="employee.FirstName for employee in employees">
<option value="">-- Select Employee</option>
</select>
然后,您可以将currentEmployee
绑定到<input>
:
<input type="text" ng-model="currentEmployee.LastName" />
哦,如果你想要你&#34; - 选择员工&#34;首先出现,在控制器中设置$scope.currentEmployee = "";
。
这是您修改后的plunker