user1189352
user1189352

Reputation: 3885

Angular Editable table not working with ng-repeat

<table class="table table-bordered">
    <tbody>
        <tr ng-repeat="playerOrTeam in template.editableTable track by $index">
            <td style="text-align: center;" ng-repeat="playerOrTeamCat in playerOrTeam track by $index">
                <input ng-model="playerOrTeamCat" type="text" class="form-control input-sm">
            </td>
        </tr>
    </tbody>
</table>

template.editableTable is a multi dimensional array just filled with standard variables. when I change one of the values in the input box and then i look at the output of the template.editable table, i don't see the changes. Am I missing something obvious?

EDIT with more details because i'm getting no responses =\

//Template Class
app.factory('Template', function () {
    var Template = function () {
          /*
          * Public Variables
          */
          this.editableTable = someMultiDimensionalTable;
      }

      /*
      * Functions
      */
      Template.prototype.SeeEditableTableContents = function () {
        console.log(this.editableTable);
      }
 }

//Main Controller
app.controller('MainController', function () {
  $scope.template = new Template();
  //etc
}

Upvotes: 0

Views: 123

Answers (2)

user1189352
user1189352

Reputation: 3885

okay i actually got it to work so that i CAN make direct in-line modifications with ng-repeat by making my multidimensional table full of objects rather than soley a value.

so by doing that, i modified the table to look like this

<table class="table table-bordered">
    <tbody>
        <tr ng-repeat="playerOrTeam in template.editableTable track by $index">
            <td style="text-align: center;" ng-repeat="playerOrTeamCat in playerOrTeam track by $index">
                <input ng-model="playerOrTeamCat.value" type="text" class="form-control input-sm">
            </td>
        </tr>
    </tbody>
</table>

got the idea looking here Modifying objects within Angular Scope inside ng-repeat

Upvotes: 0

jegtugado
jegtugado

Reputation: 5141

You cannot perform direct in-line modifications within ng-repeat. You can update your array entry using a function.

You'd want something like:

$scope.saveEntry = function (idx) {
    console.log("Saving entry");
    $scope.template.editableTable[idx] = angular.copy($scope.model.selected);
    $scope.reset();
};

See JSFiddle for sample.

Upvotes: 1

Related Questions