AngularJS: Can I use a filter to chunk an array in ng-repeat?

前端 未结 3 1220
失恋的感觉
失恋的感觉 2021-01-21 01:14

Edit to add a clear question: I have a flat array of some length and I want to put it into a tr/td type view? This might also be in a bootstrap grid or somethin

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-21 01:35

    As the filter is returning new array instances as slices, angular's ngRepeat will detect them changed (as ngRepeat uses $watchCollection internally), and will cause and infinite digest loop. There is even an issue about that, but it is abandoned since 2013: https://github.com/angular/angular.js/issues/2033

    This issue still persists if you change the snippet to contain a non-constant expression, like [[x]]:

    I am afraid you will have to move the chunking logic into the controller, or to use css to form a 4-width table.

提交回复
热议问题