0

I was trying to find a way to display a table from a 2D Array. At the moment I cant get anything to display, a simple bool 1/0 is desired. Any Advice would be appreciated.

    var Matrix = [
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
        [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1]
];


            <div id = "MatrixTable2">
            <table border="1">
                <tbody  ng-repeat="xxx in Matrix">
                    <tr width="50px">

                        <td width="50px" ng-repeat="yyy in xxx[0]"> bool {{yyy}}</td>
                    </tr>
                </tbody>
            </table>
        </div>

2 Answers 2

1

just a track by $index (so that angular can keep track of it) and you are done :-

*.html

<table border="1">
   <tbody  ng-repeat="xxx in Matrix">
        <tr width="50px">
             <td width="50px" ng-repeat="yyy in xxx track by $index">{{yyy}}</td>
        </tr>
   </tbody>
</table>

*.js

$scope.Matrix = [
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1]
];
Sign up to request clarification or add additional context in comments.

Comments

0

Drop the [0] from xxx[0]:

ng-repeat="yyy in xxx track by $index"

This assumes that Matrix is in $scope.Matrix

1 Comment

I added the track by $index clause: docs.angularjs.org/api/ng/directive/ngRepeat

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.