Hello Ionic friends !
I m facing a problem for few days that I can’t solve.
I have an array that contains object, and each object contains a photo (it will be an array of photos).
My array contains object and im displaying each object with my *NgFor
like this :
<ion-item-sliding *ngFor="let k of filtered">
<ion-item>
<button class="btn" (click)="navigate(k)">
<img src="{{k.photo}}" style="z-index:0;" >
I can get the photo for 1 item : so for exemple when I click on navigate(k) I find the photo because I am referring to one item:
- I am using a method doing this:
loadImage(key) {
firebase.storage().ref("/pictures/").child(key).getDownloadURL()
.then( (url => {
return url;
}))
So this is the problem because I am not handling only one item but an array of items…
I have been looking for method that could be called from the HTML… but there is none : only “(click)” but I want them loaded without clicking…
So after trying this way, I decided to find another way…
- Why not when I create my item : load into my field ‘photo’ of my object the url to retrieve it like this I would just have to display the image by doing src="{{k.photo}}"…
So when I am creating the instance of my item I tried to do something like this:
this.s.addItem(this.item).then((res: any) => {
this.item.seller = this.userservice.afireauth.auth.currentUser.displayName;
this.createPost(this.Picture, this.item.uid);
})```
and then the method addItem :
addItem(s : sCreds) {
s.uidOfSeller = this.userservice.afireauth.auth.currentUser.uid;
s.seller = this.userservice.afireauth.auth.currentUser.displayName;
s.date = new Date().getTime();
s.uid = firebase.database().ref('/s-list/').push(s).key;
firebase.storage().ref("/picturesOfCustom/").child(s.uid).getDownloadURL() // --> suppose to create a url and put it in s.photo
.then( (url => {
s.photo = url;
}))
return this.sneakRef.set(s.uid, s);
}```
But my s.photo is not hydrated and does not contain anything (inside the field : s.photo)
I might not doing it in the proper way?
- I also tried a method that does not work as well:
When I retrieve my items inside my array : I decided to do something like this :
this.firedataS.orderByChild('uid').once( 'value', (snapshot) => {
let userdata = snapshot.val();
let temparr = [];
for (var key in userdata) {
if (arrayUidC.indexOf(userdata[key].uidOfSeller) != -1) {
firebase.storage().ref("/pictures/").child(s.uid).getDownloadURL() // --> suppose to create a url and put it in s.photo
.then( (url => {
userdata[key].photo = url;
}))
temparr.push(userdata[key]);
resolve(temparr);
}
}
It does put the url inside an item, but only one ! (generally the last), I also tried to move the “temparr.push(userdata[key])” and the “resolve(temparr);” at different place (after : the ‘}’).
So I don’t know if at least one of my three methods is correct, I would really appreciate any help / guidance
Thanks Ionic friends!