Angularfire 2 Firebase存储嵌套订阅

时间:2017-04-18 18:31:01

标签: javascript ionic2 observable firebase-storage angularfire2

我正在准备更新表格。

我有一个组件和服务,它们使用Firebase数据库中的$ id作为Angularfire2 FirebaseObjectObservable获取帖子详细信息。

然后调用服务从pageload Ionic 2上的firebase存储中获取图像的元数据。

但是在服务获取页面加载结果后可观察到。所以表格输入总是空的。

是否可以等待回调获取firebase存储元数据然后继续?

这是组件



ionViewDidLoad()  {
    let loading = this.loadingCtrl.create({
      spinner: 'hide',
      content: 'Loading Please Wait...'
    });
   
    loading.present();
    this.categories = this.af.database.list('/Categories');
    let id = this.navParams.get('id'); 
    
    this.post = this.af.database.object(`/Posts/${id}`);
    
    this.post.subscribe(snapshot => {
      
      this.uploadImagesService.getMetaData(snapshot.postpicurl).subscribe((metadata:any) =>{
        //Set Form values   
        this.CreatePost.get('title').setValue(snapshot.title);
        this.CreatePost.get('content').setValue(snapshot.content);
        this.uploadedpic.name = metadata.name;
        this.uploadedpic.size = metadata.size;

      });
      console.log(snapshot);
      
    });
    
      
    loading.dismiss();
      
  }




这是元数据服务



getMetaData(url:string){
   return Observable.create((observer:any) => {
     let metaDataRef = firebase.storage().refFromURL(url);
     metaDataRef.getMetadata().then(function(metadata) {
      // Metadata now contains the metadata for 'images/forest.jpg'
       observer.next(metadata);
      //observer.complete(metadata);
     }).catch(function(error){
       observer.error(error);
     });
   });




1 个答案:

答案 0 :(得分:0)

我解决了这样的问题。因为我了解到火基总是回报承诺。



$cred = $host.ui.PromptForCredential("local credential", "Enter machine\user ID and password.", "localhost\$env:username", "")
$session = New-PSSession -ComputerName server2 -Credential $cred




相关问题