将angularjs 1.2升级到1.3指令ng-repeat范围问题

问题描述 投票:2回答:1

当前正在尝试从angularjs 1.2更新到1.3,并且发现了问题。该应用程序具有分页指令:

app.directive("mobilePaginationList", function() {
 return {
        restrict: 'E',
        templateUrl: "Directives/mobilePagination/List/mobilePaginationList.html",
        transclude: true,
        replace: true,
        scope: {
            list: '=list'
        },
        link: function ($scope, $element, $attributes) {
            // code removed that is not relevant
            $scope.listToDisplay = PaginationService.from(origList).getPage(page);
        }
    }

}

模板是:

<div class="row">
    <div class="col-xs-12">
        <div data-ng-repeat="currentItem in listToDisplay"  bindonce data-ng-transclude>
        </div>
        <mobile-pagination-pager data-ng-hide="vm.list.length <= 0"></mobile-pagination-pager>
    </div>
</div>

用法示例:

<mobile-pagination-list data-receipt-slider-menu-toggle="active" list="receipts" data-ng-hide="list.length <= 0 || rootVm.loading.receipts.value" class="row list-group">
        <a class="row list-group-item" data-bo-id="currentItem.attachNo" ui-sref="receiptWalletDetails({receiptId: currentItem.attachNo})">
            <div class="col-xs-11">
                <div class="row">
                    <div class="col-xs-8">
                        <h4 data-bo-bind="currentItem.description"></h4>
                    </div>
                    <div class="col-xs-4 text-right">
                        <h4 data-bo-bind="currentItem.amount | currency:''"></h4>
                    </div>
                </div>
                <div class="list-group-item-text">
                    <div class="row">
                        <div class="col-xs-8">
                            <span data-bo-bind="currentItem.notes"></span>
                        </div>
                        <div class="col-xs-4 text-right">
                            <span class="text-info"
                                data-bo-bind="currentItem.createDate | date: 'd MMM yyyy'">
                            </span>
                        </div>
                    </div>
                </div>
            </div>
        </a>
    </mobile-pagination-list>

发生的情况是ng-repeat正确显示了行数,但每一行都不包含currentItem对象的任何数据。该行的确包含所有HTML,但缺少currentItem值。

我已经对这个问题进行了很多搜索,但尚未找到解决方案。

欢呼声

angularjs directive
1个回答
1
投票

用法:

<mobile-pagination-list data-receipt-slider-menu-toggle="active" list="receipts" data-ng-hide="list.length <= 0 || rootVm.loading.receipts.value" class="row list-group"> <a class="row list-group-item" data-bo-id="$parent.currentItem.attachNo" ui-sref="receiptWalletDetails({receiptId: currentItem.attachNo})"> <div class="col-xs-11"> <h4 ng-bind="$parent.currentItem.description"></h4> <h4 ng-bind="$parent.currentItem.amount | currency:''"></h4> <span ng-bind="$parent.currentItem.notes"></span> <span class="text-info" ng-bind="$parent.currentItem.createDate | date: 'd MMM yyyy'"> </span> </div> </a> </mobile-pagination-list> 这里是带有工作示例的plunker

请注意,您的代码已修改为摆脱依赖关系。
© www.soinside.com 2019 - 2024. All rights reserved.