index.html 1.27 KB
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .error{
            border-color: darkred;
        }
    </style>
</head>
<body ng-app="test" ng-controller="ctrlTest" ng-init="validator = validator">

<ng-form name="mForm" matrix-validator data-all="validator">
    <table>
        <tr ng-repeat="row in matrix" ng-init="rowId = $index">
            <td ng-repeat="item in row track by $index">
                <input ng-model="row[$index]" type="number"
                       data-row="rowId" data-col="$index"
                       name="item{{rowId}}_{{$index}}"
                       ng-class="{error: mForm['item'+rowId+'_'+$index].$invalid}"
                >
            </td>
        </tr>
    </table>
</ng-form>

<script src="../node_modules/angular/angular.js"></script>
<script src="validatorDep.js"></script>
<script src="../src/matrix-validation.js"></script>
<script>
    angular.module('test', ['matrixValidation']).controller('ctrlTest', [
        '$scope',
        ($scope) => {
            $scope.matrix = [
                [0,0,0],
                [0,0,0],
                [0,0,0]
            ];

            $scope.test=2;

            $scope.validator = validator;
        }
    ]);
</script>
</body>
</html>