How to Bind dynamic data in textbox when user sele

2019-09-19 15:36发布

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条回答
萌系小妹纸
2楼-- · 2019-09-19 16:00

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());
查看更多
登录 后发表回答