Angular 显示的管道数据无效

Angular 显示的管道数据无效,angular,firebase,firebase-realtime-database,angularfire2,Angular,Firebase,Firebase Realtime Database,Angularfire2,我使用AngularCLI、firebase和angularfire2。我想通过选择firebase键来显示特定数据,但控制台指示管道无效。有人能帮我吗 this.patientid的值是firebase键 //HTML {{(patientToDisplay | async)?.nom}} //组成部分 import { Component, OnInit, Inject } from '@angular/core'; import { Patient } from '../../model

我使用AngularCLI、firebase和angularfire2。我想通过选择firebase键来显示特定数据,但控制台指示管道无效。有人能帮我吗

this.patientid的值是firebase键

//HTML

{{(patientToDisplay | async)?.nom}}
//组成部分

import { Component, OnInit, Inject } from '@angular/core';
import { Patient } from '../../models/patient.model';
import { ActivatedRoute, Router } from '@angular/router';
import { PatientsService } from '../../services/patients.service';
import { AngularFireDatabase, AngularFireList, AngularFireObject} from 'angularfire2/database';
import { Location } from '@angular/common';

@Component({
selector: 'app-single-patient',
templateUrl: './single-patient.component.html',
styleUrls: ['./single-patient.component.scss'],
providers: [PatientsService]
})

export class SinglePatientComponent implements OnInit {


patientId: string;
patientToDisplay;

constructor( 
private route: ActivatedRoute, 
private location: Location,
private patientsService: PatientsService,
private diagnosticsService: DiagnosticsService,
private router: Router, 
public dialog: MatDialog, 
private formBuilder: FormBuilder
) {}

ngOnInit() {
this.route.params.forEach((urlParameters) => {
this.patientId = urlParameters['id'];
});
this.patientToDisplay = 
this.patientsService.getSinglePatient(this.patientId);
console.log(this.patientId);

}

}
//服务

getSinglePatient(Patientid: string){
return this.database.object('patients/' + Patientid);
}

显示:可观察

您还应该键入此项和get req,但这是在它工作后的一种形式:)


出现无效管道错误的原因是,您从未将显示设置为可观察对象。异步管道需要一个可观察到的对象

import { Component, OnInit, Inject } from '@angular/core';
import { Patient } from '../../models/patient.model';
import { ActivatedRoute, Router } from '@angular/router';
import { PatientsService } from '../../services/patients.service';
import { AngularFireDatabase, AngularFireList, AngularFireObject} from 'angularfire2/database';
import { Location } from '@angular/common';
import { Observable } from 'rxjs/Observable'

@Component({
selector: 'app-single-patient',
templateUrl: './single-patient.component.html',
styleUrls: ['./single-patient.component.scss'],
providers: [PatientsService]
})

export class SinglePatientComponent implements OnInit {


patientId: string;
patientToDisplay: Observable<any>;

constructor( 
private route: ActivatedRoute, 
private location: Location,
private patientsService: PatientsService,
private diagnosticsService: DiagnosticsService,
private router: Router, 
public dialog: MatDialog, 
private formBuilder: FormBuilder
) {}

ngOnInit() {
this.route.params.forEach((urlParameters) => {
this.patientId = urlParameters['id'];
});
this.patientToDisplay = 
this.patientsService.getSinglePatient(this.patientId);
console.log(this.patientId);

}

}
从'@angular/core'导入{Component,OnInit,Inject};
从“../../models/Patient.model”导入{Patient};
从'@angular/Router'导入{ActivatedRoute,Router};
从“../../services/patients.service”导入{PatientsService};
从“angularfire2/database”导入{AngularFireDatabase、AngularFireList、AngularFireObject};
从“@angular/common”导入{Location};
从'rxjs/Observable'导入{Observable}
@组成部分({
选择器:“应用程序单个患者”,
templateUrl:'./single patient.component.html',
styleUrls:['./单个患者.component.scss'],
提供者:[患者服务]
})
导出类SinglePatientComponent实现OnInit{
patientId:字符串;
显示:可观察;
建造商(
专用路由:激活的路由,
私人场所:场所,
私人病人服务:病人服务,
私人诊断服务:诊断服务,
专用路由器:路由器,
公共对话:MatDialog,
私有表单生成器:表单生成器
) {}
恩戈尼尼特(){
this.route.params.forEach((urlParameters)=>{
this.patientId=urlParameters['id'];
});
此.patientToDisplay=
this.patientsService.getSinglePatient(this.patientId);
console.log(this.patientId);
}
}

如果您想从您的服务返回可观察的,请使用以下命令:

getSinglePatient(Patientid: string){
  return this.database.object('patients/' + Patientid).valueChanges();
}

@DiegoVen–ncio类型“AngularFireObject”不可分配给类型“string”。patientToDisplay:可观察;您还应该键入此项和get req,但这是在您使其工作后的一种形式:)您得到无效管道错误的原因是因为您从未将patientToDisplay建立为可观察的。异步管道需要一个可观察到的管道。当我尝试console.log(this.database.object('patients/',Patientid);)时,我有一个错误;我真的不使用firebase,所以我不能帮你,但这似乎与你原来的问题无关。@Sanndra Willford感谢Sandra,但我不喜欢这样:src/app/patient list/single patient/single patient.component.ts中的错误(38,4):错误TS2322:类型“AngularFireObject”不可分配给类型“Observable”。类型“AngularFireObject”中缺少属性“\u isScalar”。请尝试
可观察的
也许有一个更简单的解决方案?此时您需要设置stackblitz或plunker,以便真正深入任何地方,我没有选择,无法直接使用它。这很有意义。我在Firebase上没有跟上速度,所以我下面的答案可能不是100%是的,谢谢桑德拉·西尔福德和萨沙姆·古普塔,它工作得很好