Reputation: 63
I've used angular CLI 6 and firebase.
I have two classes for interfaces: pps and ppsplan.
export class PPS { constructor (
public Patientid : string,
public traitement: string,
public description: string,
public effetsind,
public ppsplan,
public Esresp: string,
public medresp: string,
public contactmail:string,
public contacttel: string
) {}
}
export class Ppsplan { constructor(
public typetraitement:string,
public acte:string,
public duree:number,
public datedebut = new Date(),
public datefin = new Date()
) {} }
I record ppsplan inside pps as an array.
I want to get :
this.data1 = [
["typetraitement", "enddate", "end date"],
["value1.typetraitement", "value1.datedebut", "value1.datefin"],
["value2.typetraitement", " value2.datedebut "," value2.datefin "]
]
When I browse the object pps I would like to find the values contained in the ppsplan array corresponding to interestingFeilds.
Component
ngOnInit() {
this.ppssToDisplay = this.ppssService.getPPSByPatientid(this.patientid);
let interestingFields = [ 'typetraitement','datedebut', 'datefin'];
this.ppssToDisplay.subscribe(ppsList => {
this.data1 = [
interestingFields,
...ppsList.map(pps => interestingFields.map(field =>pps[field]))
];
});
this.config1 = new GanttChartConfig( '',new Date (),new Date ());
this.elementId1 = 'myGanttChart';
}
Service
getPPSByPatientid(Patientid: string){
return this.database.list('/ppss', ref => ref.orderByChild("Patientid").equalTo(Patientid)).snapshotChanges().pipe(map(actions => {
return actions.map(a => {
const data = a.payload.val();
const key = a.payload.key;
return {key, ...data };
});
})); }
My subscribsion doesn't work. console.log(this.data1) said me
(2) [Array(3), Array(3)]
0:(3) ["typetraitement", "datedebut", "datefin"]
1:Array(3)
0:undefined
1:undefined
2:undefined
Upvotes: 1
Views: 141
Reputation: 63
I made this but now, my data are duplicated when i add one data.
ngOnInit() {
this.route.params.forEach((urlParameters) => {
this.patientid = urlParameters['id'];});
this.patientToDisplay = this.patientsService.getSinglePatient(this.patientid);
this.diagnosticsToDisplay = this.diagnosticsService.getDiagnosticByPatientid(this.patientid);
this.ppssToDisplay = this.ppssService.getPPSByPatientid(this.patientid);
this.sossToDisplay = this.sossService.getSOSByPatientid(this.patientid);
this.ppsdocsToDisplay = this.docsService.getPpsDocByPatientid(this.patientid);
let interestingFields = [ 'typetraitement','datedebut', 'datefin'];
let data1=[interestingFields];
this.ppssToDisplay.subscribe((ppsList: PPS[]) => {
console.log(ppsList);
ppsList.map((pps: PPS) => {
Object.keys(pps.ppsplan).forEach(key => {
let ppsplan: Ppsplan = pps.ppsplan[key];
data1.push([
...interestingFields.map(field => ppsplan[field])
]);
});
console.log(data1);
});
this.data1 = data1;
});
Upvotes: -1
Reputation: 64
Based on your structure, it seems as though you are subscribing to the ppss, but expecting to get a pps List. Shouldn't your subscription return the ppss, then you get the ppsList from the pps.ppsplan array?
Each PPS object will contain an object that simulates an array with indexes '0', '1', etc... You will need to use Object.keys to iterate over the properties of the object to get to the individual Ppsplan objects.
Upvotes: 2