But perhaps there is a better solution that avoids putting view logic
into the controller...
Forgot the link: http://jsfiddle.net/YUVWP/
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en.
Actually Philipp, you may have a point. Rereading the original question it appears we got a little off topic.I started to think of ways I could quickly take an array and return a new array of slices of the original, but off the top of my head I don't have a quick solution.In that situation, your filter might be kinda handy. You should fork AngularUI and submit a pull request :) although the logic could be cleaned up a little.Honestly though, I tend to do the aforementioned solely using CSS.I find that even the use of a filter (or angular itself) to control this sort of view-specific logic is too restrictive. If you use CSS floats (to auto-wrap) and percentage widths, or simply use the new CSS columns then you can adjust how many columns you have per row on a device/screen-size basis, allowing for responsive design.Not to mention no unnecessary wrapper DOM elements :)
On Wed, Aug 1, 2012 at 3:08 AM, Philipp Burgmer <ma...@deflip.de> wrote:
Limit, StartFrom and Splice are options if you know how many items you have.I think the group filter, which I posted, has the advantage to be independent of the number of items.With all the other options, you do a outer repeat manually to create the rows and you have to know how many items will be there.What do you think?
Am Mittwoch, 1. August 2012 01:14:53 UTC+2 schrieb Ricardo Bin:Yes!I use this way to limit arrays in angular.
Em terça-feira, 31 de julho de 2012 19h47min05s UTC-3, Andy Joslin escreveu:So apparently, as someone just showed me, Javascript has a slice function (which does work in all browsers). So you could just do<div class="group1"><span ng-repeat="item in items.slice(0,3)"></div>
<div class="group2"><span ng-repeat="item in items.slice(3,6"></div>
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en.
['$rootScope',
function($rootScope) {
makeSlices = function(items, count) {
if (!count)
count = 1;
if (!angular.isArray(items) && !angular.isString(items)) return items;
var array = [];
for (var i = 0; i < items.length; i++) {
var chunkIndex = parseInt(i / count, 10);
var isFirst = (i % count === 0);
if (isFirst)
array[chunkIndex] = [];
array[chunkIndex].push(items[i]);
}
if (angular.equals($rootScope.arrayinSliceOf, array))
return $rootScope.arrayinSliceOf;
else
$rootScope.arrayinSliceOf = array;
return array;
};
return makeSlices;
}]
Hi guys,The Phillip filter is nice but his function is called N times during the iteration.