Thursday 15 September 2011

angularjs - How to bind properties to input fields from selectoin box selection -



angularjs - How to bind properties to input fields from selectoin box selection -

can't figure out how bind properties of object select box. plunker

<select ng-model="currentemployee.firstname" ng-options="employee.employeeid employee.firstname 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; };

for case don't need utilize ng-change.

set ng-model actual employee object , bind $scope.currentemployee.

<select ng-model="currentemployee" ng-options="employee.firstname employee in employees"> <option value="">-- select employee</option> </select>

then, bind currentemployee <input>:

<input type="text" ng-model="currentemployee.lastname" />

oh, , if want "-- select employee" appear first, set $scope.currentemployee = ""; in controller.

here's modified plunker

angularjs

No comments:

Post a Comment