通过angularjs动态添加产品到商店

时间:2013-10-13 09:00:06

标签: angularjs

我有一个商店网页,我想在用户向下滚动时添加产品块(通过无限滚动)。

我应该使用哪种方法从服务器获取数据并将其添加到dom?

我看到这个fiddle用于在angularjs中实现无限滚动(当用户到达页面末尾时它运行loadMore()函数),如上所述,块是商店的产品,每个项目应该具有不同的范围。

问题在于我不知道如何在作用域中构建数据并通过loadMore()函数中的ajax请求向其添加更多项目。

我的产品模板:

<section class="more-apps">
    <h1>More recommendations</h1>
    <div class="loadmore-these">
        <!-- ajax requests will load more instances of these three templates -->
        <div data-ng-include data-src="'products-template-1.html'"></div>
        <div data-ng-include data-src="'products-template-2.html'"></div>
        <div data-ng-include data-src="'products-template-3.html'"></div>
    </div>
</section>

并且每个子模板文件都是这样的,但有一些简单的区别:

<section data-ng-repeat="i in [1,2,3,4]">
<h1 data-ng-bind-html="title"></h1>
    <div data-ng-bind-html="about"></div>
</section>

每个产品在(它自己的?)范围内都有不同的titleabout变量。

1 个答案:

答案 0 :(得分:0)

我建议你浏览angularjs官方教程(基本上是关于你想做什么,从网上商店列出产品),特别是关于$ http和服务的步骤:

http://docs.angularjs.org/tutorial/step_05

如果您根据用户滚动的数量(例如您链接的示例)构建服务以下载一系列产品,则应设置。