I have a special filter that alters the objects being filtered. However, when I apply ng-style="item.gridSize"
, it triggers my custom grid algorithm. This algorithm was adapted for my requirements from a source found at this link.
angular.module("custom.modules.photoGrid", []).filter('photoSearch', [function () {
// Custom grid algorithm here
}]);
HTML:
<input type="text" ng-model="input.value"> <span>{{ results.length }}</span> Photos Found
<div ng-repeat='photo in photos | photoSearch:input.value as results track by photo.id' class="photo-item" ng-style="photo.gridSize">
<img ng-src="/photos/{{photo.url}}">
</div>
A brief explanation:
Whenever ng-model
input.value
changes, the filter is triggered to create a new grid layout for the filtered photos array. The dimensions are specified within gridSize
, which may lead to digest loop issues.
Attempts made so far:
I attempted moving the ng-repeat
into a directive, but this hindered accessing result.length
and input.value
.
Another experiment involved using the bindonce
directive with bo-style="photo.gridSize"
. However, this didn't update the grid post-user search due to its one-time binding nature.
Hence, my question remains: How can I adjust ng-repeat
to assign a new gridSize
property without causing a digest loop?
UPDATE: See the JSFiddle here.
Working Fiddle: Check out the functional version on JSFiddle here.