How to Bind dynamic data in textbox when user sele

2019-09-19 15:48发布

问题:

I am using AngularJS - 1.0.6 version. I have created sample application where I want data to be populated in the textbox when user selects row in a grid. I have a directive which will render textbox and bind data with ng-model property. The model which binds the data with ng-model is dynamic. for e.g. - input.attr('ng-model', 'model["' + d.id.toLowerCase() + '"]');

I need to use Angular.copy method to copy selected Items data into another model object.

$scope.model = angular.copy($scope.selectedItems);

I have used the same model to bind Textbox and Label. The selected data is shown in Label but not in Textbox. Here is a plunkr link with sample -

http://plnkr.co/edit/948JfxAF8lbyq1xa3Fyu?p=preview

Can anyone help me to find the solution for it?

Thanks in advance!!!

回答1:

I updated your plunker with a working example. You are going to have to pass in the index of the selected item to your dynamic input control. Plunker

input.attr('ng-model', 'model[0].' + d.id.toLowerCase());