Comments (16)
@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.
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.
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.
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.
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.
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.
Could you give a short example on how to accomplish that? There is no prepend on NgxMasonryComponent, only add.
from ngx-masonry.
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.
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.
Hi, try the new release with option prepend
!
<div ngxMasonryItem [prepend]="image.prepend" *ngFor="let image of masonryImages">
from ngx-masonry.
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.
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.
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.
@yingwei1025 seems like you didn't push the first item to cardItems?
from ngx-masonry.
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.
@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)
- masonry is break when is on chrome print pdf pre-viewer
- fitWidth broke the resize behavior
- Window is not defined issue after updating to angular v16 HOT 4
- not import in standalone component HOT 1
- SSR: ngOnDestroy generate "Cannot read property 'remove' of undefined" HOT 1
- fitWidth breaks resize HOT 7
- Unable to resolve dependency tree (i'm using Angular 11.x) HOT 1
- Centering items inside the ngx-masonry
- Dynamic responsiveness HOT 2
- Dynamic loading of masonryItems HOT 3
- Angular 13 Support HOT 6
- Could you provide the "live example" repo in README? HOT 1
- 'ngx-masonry' is not a known element HOT 1
- Change array order breaks masonry template 🤔 HOT 5
- How to set containerStyle? HOT 4
- support for angular 14 HOT 4
- Support for Angular 13 HOT 3
- Angular 14 - 'NgxMasonryModule' does not appear to be an NgModule class. HOT 1
- Tests failing with the message ReferenceError: require is not defined HOT 6
- Reference Error: window is not defined Angular 14 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngx-masonry.