【问题标题】:Scrolling HTML data with angular.js使用 angular.js 滚动 HTML 数据
【发布时间】:2017-01-06 18:32:14
【问题描述】:

我正在尝试使用 angular.js 重复具有 html 数据的列表。 我想使用ngInfiniteScroll

所以我已经建立了一个模板,就像这样。

更新:

<div class="scroll" id="antTalkList" talk-type="total" view-type="total"
    infinite-scroll='$ctrl.loadMore()' infinite-scroll-distance='2'>
    <ul class="user_list list ng-scope" ng-repeat="item in $ctrl.htmlViews">
        <ng-bind-html ng-bind-html="item"> </ng-bind-html>
</ul>
</div>

正如你在上面看到的,我不知道如何在ul 中重复$ctrl.htmlViews。每个 htmlViews 的 item 都用上面的 HTML 数据填充。

&lt;li ... &gt; ... &lt;/li&gt; ... &lt;li ... &gt; ... &lt;/li&gt;

这是我的antList 组件。在控制器中,htmlViews在控制器初始化和滚动时通过ajax调用推送(loadMore函数)。

ng-repeat 似乎还可以,也许它运作良好。但是,infinite-scroll 不起作用。我添加了infinite-scroll="$ctrl.loadMore()"infinite-scroll-distance='10'

LoadMore 函数在初始化时被调用,但在我滚动时它不会被调用。我该如何检查这种情况?

这是我的组件 sn-ps。

.component('antList', {
    templateUrl : 'templates/ant-list.html'
    , controller : function AntListController($http, $attrs, $sce){
        var self = this;
        this.htmlViews = [];
        this.loading = false;

        $http({
            method : "GET",
            url : "ant/list?sectionId="+$attrs.talkType+"&pageCount=20&startIndex=0"
        }).then(function mySucces(response) {
            self.htmlViews.push($sce.trustAsHtml(response.data));
        });

        this.loadMore = function(){
            $http({
                method : "GET",
                url : 'ant/list?pageCount=20&startIndex=' 
                    + $('#antTalkList .user_list li').size()
                    + '&sectionId=' +$attrs.talkType
            }).then(function mySucces(response) {
                self.htmlViews.push($sce.trustAsHtml(response.data));
            });
        }
    }
})

【问题讨论】:

  • 您应该使用$comple 来编译您的模板。
  • @gianlucatursi 嗯,我找到了。也许我是个愚蠢的人,需要在 ul 标签中重复 ng-repeat。模板没有问题。我会更新其他内容。
  • 操作。对不起。我不明白这个问题。我认为下面的解决方案是正确的。
  • @gianlucatursi 没关系 :),我可以改变我的问题吗?
  • 其实我滚动的时候加载数据不好用,这是个问题。

标签: javascript angularjs


【解决方案1】:
<div class="scroll" id="antTalkList" talk-type="total" view-type="total"
    infinite-scroll='loadMore()' infinite-scroll-distance='2'>
    <ul class="user_list list ng-scope">
        <li ng-repeat="view in htmlViews">
         {{view}}
        </li>
    </ul>
</div>

【讨论】:

  • 非常感谢。你太快了,但我应该更新我的问题。 :(
猜你喜欢
  • 2017-01-07
  • 2014-03-01
  • 2016-09-23
  • 2017-03-26
  • 1970-01-01
  • 2013-06-10
  • 2021-07-26
  • 2015-04-25
  • 1970-01-01
相关资源
最近更新 更多