我在使用 yeoman 生成的 Angular 应用程序中有以下代码
'use strict';
function CoffeeListCtrl($scope, $http) {
$http.get('data/coffee.json').success(function(data) {
$scope.coffees = data;
});
$scope.orderProp = 'name';
$scope.orderType = '';
$scope.goTo = function (path) {
$location.path(path);
}
$scope.showNresults = function (n) {
if (n==-1) {
return $scope.coffees.length;
} else {
return n;
}
//REVIEW: code optimization .. shrink version
// message = ('Stephen' === name) ? "Welcome back Stephen" : "Welcome " + name;
}
$scope.numberOfPages=function(itemsPerPage){
if (itemsPerPage == -1) itemsPerPage=$scope.coffees.length;
return Math.ceil($scope.coffees.length/itemsPerPage);
}
}
知道为什么我可能会得到以下控制台输出
更新 具有以下 html 代码段:
<div class="row-fluid">
<ul class="coffees">
<li class="span4 coffeeitem" ng-repeat="coffee in (filteredItems = (coffees | filter:query | orderBy:orderProp | filter:orderType | startFrom: (currentPage*resultspp)-resultspp | limitTo: showNresults(resultspp)))">
<a href="#/coffees/{{coffee.id}}">{{coffee.name}}</a>
<p>{{coffee.basicInfo}}</p>
<button class="coffeebutton" type="button">Add to list</button>
</li>
<p ng-show="(coffees | filter:query).length == 0" id="message">No coffee found, please refine your search</p>
</ul>
</div>
并确定了导致我循环依赖错误的以下内容startFrom: (currentPage*resultspp)-resultspp | limitTo: showNresults(resultspp)