使用角度4访问firebase中的数据

时间:2018-01-05 16:21:40

标签: angular firebase angularfire

当我使用angular 4时,我可以访问firebase中的数据... 在规则firebase我修改为:

  

{     “规则”:{       “.read”:是的,       “.write”:是的     }   }

但也有错误我显示数据Firebase,我有这个结果:

enter image description here

代码服务:

import { Injectable } from '@angular/core';
    import { AngularFireDatabase, AngularFireList} from 'angularfire2/database';
    import { FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2/database-deprecated';
    import { Observable} from 'rxjs';
    import { Employee } from '../Employee';

    @Injectable()
    export class EmployeeService {

    employees:AngularFireList<any[]>;
    Employee:FirebaseObjectObservable<any>;

      constructor(public af:AngularFireDatabase) {
        this.employees = this.af.list('/employeesdb') ;
       }

       getEmployees(){
        return this.employees;
       }

    }

代码组件:

import { Component, OnInit } from '@angular/core';
    import { EmployeeService } from '../../services/employee.service';
    import { Employee } from '../../Employee';

    @Component({
      selector: 'app-employees',
      templateUrl: './employees.component.html',
      styleUrls: ['./employees.component.css']
    })
    export class EmployeesComponent implements OnInit {
    employees: Employee[];

      constructor(public employeeService: EmployeeService) { 

      }

      ngOnInit() {
        /*this.employeeService.getEmployees().subscribe(employees => {
            this.employees = employees;
        });*/
        console.log(this.employeeService.getEmployees());

      }

    }

0 个答案:

没有答案