Masonry with AngularJS

后端 未结 6 1513
情书的邮戳
情书的邮戳 2021-01-29 22:28

I am developing an \"art gallery\" app.

Feel free to pull down the source on github and play around with it.

Plunker with full

6条回答
  •  执笔经年
    2021-01-29 22:59

    Rather than using two directives you could incorporate them both into one directive. Something like:

    .directive("masonry", function($timeout) {
        return {
            restrict: 'AC',
            template: '
    ' + '{{image.albumTitle|truncate}}' + '' + '
    ', scope: { pool: "=" }, link: function(scope, elem, attrs){ elem.masonry({itemSelector: '.masonry-brick'}); // When the pool changes put all your logic in for working out what needs to be prepended // appended etc function poolChanged(pool) { //... Do some logic here working out what needs to be appended, // prepended... // Make sure the DOM has updated before continuing by doing a $timeout $timeout(function(){ var bricks = elem.find('.masonry-brick'); brick.imagesLoaded(function() { // ... Do the actual prepending/appending ... }); }); } // Watch for changes to the pool scope.$watch('pool', poolChanged, true); // The final true compares for // equality rather than reference } } });

    and html usage:

提交回复
热议问题