0

I need to add rows and inputs dynamically, in addition to filling each entry in these fields, but at the moment of wanting to fill the input I get a error, with this add the rows:

    $scope.detalleTransCover = {
        details: []
    };
    $scope.addDetail = function () {
        $scope.detalleTransCover.details.push('');
    };
    $scope.submitTransactionCobver = function () {
        angular.forEach($scope.detalleTransCover, function(obj)
        {
           console.log(obj.cuenta);
        });
    };

now in the html:

<tr ng-repeat="detail in detalleTransCover.details">
    <td>
        <input type="text" class="form-control" ng-model="detail.cuenta">
    </td>
    <td>
        <input type="text" class="form-control" ng-model="detail.debeDolar">
    </td>
    <td>
        <input type="text" class="form-control" ng-model="detail.haberDolar">
    </td>
</tr>

<button ng-click="addDetail()" class="btn btn-block btn-primary">
    Agregar fila
</button>
<button ng-click="submitTransactionCobver()" class="btn  btn-block btn-primary">
    Agregar
</button>

on the html when I try to fill the input example "cuenta" haver error:

TypeError: Cannot create property 'cuenta' on string ''
0

1 Answer 1

1

When you push a new input to your array, you need to push an object not a string:

// wrong
$scope.addDetail = function () {
    $scope.detalleTransCover.details.push('');
};

// right
$scope.addDetail = function () {
   $scope.detalleTransCover.details.push({})
});

Strings can't have properties the same way objects can.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.