ng-repeat不能处理指令上的对象数组

时间:2017-07-13 08:16:06

标签: angularjs angularjs-directive angularjs-ng-repeat angular1.6

我有一个directive,如下所示。变量testDataWithPlantNumberAsKey[plantnumber]在父控制器中定义,并在其中包含数据。它是Objects的数组。它由以下代码中的{{$parent.testDataWithPlantNumberAsKey[plantnumber]}}打印。 当我ng-repeat时,它不起作用,也不会抛出错误。我错过了什么?

<div id="test-data" class="test-data-table">
        <h3 style="text-align:center;" ng-if="!testDataWithPlantNumberAsKey[plantnumber]">No test Data</h3>

        {{$parent.testDataWithPlantNumberAsKey[plantnumber]}}
        <table ng-if="$parent.testDataWithPlantNumberAsKey[plantnumber]" class="left">
            <tr>
                <th>test</th>
                <th>Item Description</th>
                <th>Capacity</th>
                <th>Updated</th>
            </tr>
            <tr ng-repeat="data in $parent.testDataWithPlantNumberAsKey[plantnumber]  track by $index">
                <td>{{data.test}}

                </td>
                <td>{{data.itemDescription}}</td>
                <td>{{data.amount}}/{{data.testCapacity}}</td>
                <td>{{data.lastUpdatedDate | date :"h:mm" }}</td>
            </tr>
        </table>
    </div>

testDataWithPlantNumberAsKey[plantnumber]看起来如下

[{"plant_":" 0205","plantName":"Mrs. Edgardo Lockman LTD ","test":"1A ","item_":"30100060 ","itemDescription":"AC BASE 301 ","amount":0,"testCapacity":200,"plantCapacityPerHour":350,"plantCapacityPerShift":3000,"lastUpdatedDate":"2017-01-19T16:45:00","lasttestTransaction":251355},{"plant_":" 0205","plantName":"Mrs. Edgardo Lockman LTD ","test":"1B ","item_":"14800060 ","itemDescription":"AC SURFACE 448 TY 1 ","amount":0,"testCapacity":200,"plantCapacityPerHour":350,"plantCapacityPerShift":3000,"lastUpdatedDate":"2017-01-19T16:45:00","lasttestTransaction":251355},{"plant_":" 0205","plantName":"Mrs. Edgardo Lockman LTD ","test":"1C ","item_":"14800060 ","itemDescription":"AC SURFACE 448 TY 1 ","amount":0,"testCapacity":220,"plantCapacityPerHour":350,"plantCapacityPerShift":3000,"lastUpdatedDate":"2017-01-19T16:45:00","lasttestTransaction":251355}]

1 个答案:

答案 0 :(得分:0)

好的,我遇到了问题,它使用了ng-if创建了一个不同的范围,而$ parent指的是前一个范围!