I am developing an "art gallery" app.
Feel free to pull down the source on github and play around with it.
The current work around for getting Masonry to play nice with Angular:
.directive("masonry", function($parse) {
return {
restrict: 'AC',
link: function (scope, elem, attrs) {
elem.masonry({ itemSelector: '.masonry-brick'});
}
};
})
.directive('masonryBrick', function ($compile) {
return {
restrict: 'AC',
link: function (scope, elem, attrs) {
scope.$watch('$index',function(v){
elem.imagesLoaded(function () {
elem.parents('.masonry').masonry('reload');
});
});
}
};
});
This doesn't work well because:
- As the content grows, so does the overhead of tiggering reload on the entire container.
The reload function:
- Does not "append" items, rather re-arranges every item in the container.
- Does work for triggering a reload when items are filtered out of a result set.
In context with the app I've given links to above, this problem becomes very easy to replicate.
I am looking for a solution that will use directives to leverage:
.masonry('appended', elem) and .masonry('prepended', elem)
Rather than executing .masonry('reload') every time.
.masonry('reload') for when elements are removed from result set.
EDIT
The project has been updated to use the working solution below.
Grab the source on GitHub
See a working version on Plunker
reload? Looking at the source for the Masonry adding items example page, it seems that they're triggering a reload when prepending items:$container.prepend($boxes).masonry('reload');.masonry('prepended', elem)--- hopefully that will be an easy one to implement..masonry('appended', elem)however seems like it's going to be a real problem.