0

I am using a table with dynamic number of rows, each row which will have a combination of dropdowns as well as input text boxes. I am concerned on how to obtain the values of textboxes and dropdown specific to that corresponding row.

I have tried in obtaining the values for dropdowns like:

HTML:

 <td>
     <select class="custom-select" ng-model="selectionModel[row.number]"
             ng-change="optionChanged(row.number, selectionModel[row.number])"
             ng-options="choice.name for choice in possibleOptions track by choice.id">
     </select>
 </td>

JS:

$scope.selectionModel = {};
angular.forEach($scope.record, function(cus) {
    $scope.selectionModel[cus.number] = $scope.possibleOptions.filter(function(opt) {
        return opt.id === cus.option;
    })[0];

});

function getUniqueValues(array, prop) {
    return [...new Set(array.map(item => item[prop]))];
}

On the dropdown change, I have created a function that is capturing whether the value is changed or not, and store the changed value in an array. This is now working fine.

I am now little stuck on how to do the same for the text box. How do I get the values of text box individually with respect to table rows?

My text box looks like:

<td>
   <input type="text" class="form-control" style="font-size:0.9rem !important;" 
          id="commentsId" placeholder="Comments" ng-model="comments"
          ng-bind="row.comments"/>
</td>

Please guide.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Mike
  • 721
  • 1
  • 17
  • 44
  • Avoid using the `ng-bind` directive and the `ng-model` directive on the same element. The `ng-model` directive should be used for two-way binding to `` elements. The `ng-bind` directive is used for one-way binding on non-input elements. – georgeawg Feb 14 '19 at 19:04
  • The `ng-repeat` directive creates a child scope which can have a data hiding problem. This can be avoided by following the rule of "always have a dot in your ng-models". For more information, see [What are the nuances of scope prototypal / prototypical inheritance in AngularJS?](https://stackoverflow.com/questions/14049480/what-are-the-nuances-of-scope-prototypal-prototypical-inheritance-in-angularjs). – georgeawg Feb 14 '19 at 19:08

0 Answers0