Giter Site home page Giter Site logo

Comments (16)

wynfred avatar wynfred commented on May 22, 2024 1

@ifumi right, put the items to an array like pendingItems, and use an event from image item
<img src="{{imageUrl}}" (load)="loaded.emit()" (error)="loaded.emit()">.
When your masonry component gets the loaded event do
this.cardItems.push(this.pendingItems.shift());

from ngx-masonry.

wynfred avatar wynfred commented on May 22, 2024

https://github.com/wynfred/ngx-masonry#faq

Images are downloaded asynchronously so the order is not guaranteed. I have plan to support synchronous loading but it's gonna take time.

from ngx-masonry.

ifumi avatar ifumi commented on May 22, 2024

Is there a way to implement synchronous loading of the images myself? So basically wait for each image in the array to be loaded before setting the next image?

from ngx-masonry.

ifumi avatar ifumi commented on May 22, 2024

Great! Thank you for making that clear for me. I got it working that way and it also looks super smooth now with the images loading one by one!

from ngx-masonry.

ifumi avatar ifumi commented on May 22, 2024

But this means, there is no way to add items to the beginning of the masonry without reloading the whole view, right?

from ngx-masonry.

wynfred avatar wynfred commented on May 22, 2024

There is a prepend function but no insert, so you can add items to the beginning but not in the middle. https://masonry.desandro.com/methods.html#prepended

from ngx-masonry.

ifumi avatar ifumi commented on May 22, 2024

Could you give a short example on how to accomplish that? There is no prepend on NgxMasonryComponent, only add.

from ngx-masonry.

wynfred avatar wynfred commented on May 22, 2024

you can access the masonry instance and call any native functions you need https://github.com/wynfred/ngx-masonry/blob/master/src/lib/ngx-masonry.component.ts#L35

change this to prepended https://github.com/wynfred/ngx-masonry/blob/master/src/lib/ngx-masonry.component.ts#L107

from ngx-masonry.

ifumi avatar ifumi commented on May 22, 2024

Ok, but how would I do this in my case with a new "app-image-wall-post" component?
To clarify my problem: Im getting images from a database when a user uploads a new image, and I always want to display the newest image at the top -> e.g. add a new app-wall-post-component with the corresponding image to the beginning. How would I add this component dynamically from my code to the masonry?

Sorry if my questions are silly, but I'm quite new to web/angular development.

from ngx-masonry.

wynfred avatar wynfred commented on May 22, 2024

Hi, try the new release with option prepend!
<div ngxMasonryItem [prepend]="image.prepend" *ngFor="let image of masonryImages">

from ngx-masonry.

yingwei1025 avatar yingwei1025 commented on May 22, 2024

Hi wynfred, i also face this not in order problem when card div have to load the image, without image is work fine

i using prepend but it seem no work, am I use it incorrect?

<ngx-masonry [options]="masonryOptions">
<mat-card ngxMasonryItem [prepend]="post.prepend" *ngFor="let post of eventPostList">
<img mat-card-image src="{{ post.cardImgUrl }}" />
<mat-card-content fxLayout="column">
<span>{{ post.postTitle }}</span>
<span>Post : {{ post.postDate }}</span>
<p align="justify">{{ post.postDesc }}</p>
</mat-card-content>
</mat-card>
</ngx-masonry>

from ngx-masonry.

wynfred avatar wynfred commented on May 22, 2024

HI @yingwei1025 , prepend doesn't help get items ordered. You could read the first 3 comments about how to load an ordered list. LMK if you have any questions.

from ngx-masonry.

yingwei1025 avatar yingwei1025 commented on May 22, 2024

Hi wynfred, I try to apply the solution u provide in 3rd comment to my code but not sure why it no work

my html

<ngx-masonry [options]="masonryOptions">
   <mat-card ngxMasonryItem *ngFor="let post of cardItems" class="grid-item">
     <img mat-card-image src="{{ post.imgURL }}" (load)="loaded()" (error)="loaded()"/>
     <span>{{ post.title}}</span>
  </mat-card>
</ngx-masonry>

my ts

export class NewComponent implements OnInit {
    cardItems: any[];
    pendingItems: any[];
    masonryOptions: NgxMasonryOptions = {
        horizontalOrder: true,
        itemSelector: '.grid-item',
    };

    constructor() {}

    ngOnInit() {
        this.getTestList();
    }

    public geTestList() {
        this.pendingItems= [{
                imgURL: 'https://material.angular.io/assets/img/examples/shiba2.jpg',
                title: 'Post 1',
            },
            {
                imgURL: 'https://material.angular.io/assets/img/examples/shiba2.jpg',
                title: 'Post 2',
            },
            {
                imgURL: 'https://material.angular.io/assets/img/examples/shiba2.jpg',
                title: 'Post 3',
            }
        ]
    }

    public loaded() {
        this.cardItems.push(this.pendingItems.shift());
    }

}

from ngx-masonry.

wynfred avatar wynfred commented on May 22, 2024

@yingwei1025 seems like you didn't push the first item to cardItems?

from ngx-masonry.

yingwei1025 avatar yingwei1025 commented on May 22, 2024

Hi @wynfred , based on your solution this.cardItems.push(this.pendingItems.shift()); means that you push the first item to cardItems when image load ?
But I not sure why console.log(this.pendingItems.shift()) is empty means that it also push empty to cardItems

from ngx-masonry.

wynfred avatar wynfred commented on May 22, 2024

@yingwei1025 yes, but you didn't call it in onInit. You need to either initialize the cardItems with one item or call loaded when it's initialized.

from ngx-masonry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.