我一直得到Type'void'不能分配给'FirebaseListObservable <any>'

时间:2017-06-20 07:51:52

标签: angular typescript

我试图获取一个列表,但是当我打电话给

时,我一直收到这个错误
this.users = this.userProvider.getAllUsers();
  

[ts]类型'void'不能分配给类型   'FirebaseListObservable'。

我尝试了一切,但我无法让它发挥作用。它曾经在我添加$ {nCompany}节点之前工作。我真的希望你能帮我一把!

谢谢!

users.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database'
import { UserProvider } from '../../providers/user/user-provider';
import { ChatViewPage } from '../chat-view/chat-view';
import { Observable } from 'rxjs/Rx';

@Component({
    templateUrl: 'users.html'
})
export class UsersPage {
    users:FirebaseListObservable<any>;
    uid:string;
    sPictureURL:string;

    constructor(public nav: NavController, public userProvider: UserProvider) {}

    ngOnInit() {
        this.userProvider.getUid()
        .then(uid => {
            this.uid = uid;
            this.users = this.userProvider.getAllUsers();
        });
    };

用户provider.ts

import { Injectable } from '@angular/core';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';

import firebase from 'firebase/app';
import { Observable } from 'rxjs/Rx';

import { Storage } from '@ionic/storage';
import { Camera, CameraOptions } from '@ionic-native/camera';

@Injectable()
export class UserProvider {
  constructor(public db: AngularFireDatabase, public local: Storage, private camera: Camera) { }

  // Get Current User's UID
  getUid() {
    return this.local.get('uid'); 
  }

  // Get Current Company
  getnCompany() {
    return this.local.get('nCompany'); 
  }  

  // Get Info of Single User
  getUser() {
    // Getting UID of Logged In User
    this.getUid().then(uid => {
      return this.db.object(`/users/${uid}`);
    });
  }


  // Get All Users of a company
  getAllUsers()  {
    this.getnCompany().then(nCompany => {
      return this.db.list(`/companies/${nCompany}/users`);
    });

  }

1 个答案:

答案 0 :(得分:0)

如果我使用

,我不明白
  // Get All Users of a company
  getAllUsers()  {
      return this.db.list('/companies/01/users');

工作正常......可能我只是累了......