Firebase storage and angularfire2

2019-02-11 08:28发布

How do to get the images from Fire base storage using angular fire 2. Thanks a lot!

constructor(public af: AngularFire) {
this.items = af.database.list('/message');
this.picture = af.database.list('/profile');
}

2条回答
Anthone
2楼-- · 2019-02-11 09:10

Right now there isn't an official integration with AngularFire2 and Firebase Storage. However, it's quite easy to use the regular SDK.

@Component({

})
class MyComponent {
  image: string;
  constructor() {
    const storageRef = firebase.storage().ref().child('path/image.png');
    storageRef.getDownloadURL().then(url => this.image = url);
  }
}

Then in your template

<img [src]="image" />
查看更多
小情绪 Triste *
3楼-- · 2019-02-11 09:10

Since you are using AngularFire2, it is a good idea to access firebaseApp (firebase instance) inside AngularFire2 module. Here is the original solution.

import { Component, Inject } from '@angular/core';
import { FirebaseApp } from 'angularfire2';

@Component({
  template: '<p>testing</p>'
})
export class AnyComponent {

  constructor(@Inject(FirebaseApp) firebaseApp: any) {
    const storageRef = firebaseApp.storage().ref().child('images/image.png');
    storageRef.getDownloadURL().then(url => this.image = url);
  }
}
查看更多
登录 后发表回答