Ich habe:
carico.model.tsmd-Datepicker + reaktive Formen + + Feuerbasis Winkel 4
export class Carico {
$key: string;
dataCarico: Date;
riferimentoCarico: string;
dettaglio:{
carburante: string;
quantita: string;
}
}
in meinem Dienst:
carichi.service.ts
import { Injectable } from '@angular/core';
....some code...
import { Carico } from './carico.model';
@Injectable()
export class CarichiService {
...some code...
getCarichiList(query = {}): FirebaseListObservable<Carico[]> {
if (!this.userId) return;
this.carichi = this.db.list(`carico/${this.userId}`, { query: query }
);
return this.carichi
}
...some code...
createCarico(carico: Carico): void {
this.carichi.push(carico)
.catch(error => this.handleError(error))
}
}
in Meine Formularkomponente:
new-carico-form.component.ts
import { Carburante } from '../../impostazioni/carburanti/carburante.model';
import { CarburantiService } from '../../impostazioni/carburanti/carburanti.service';
...some code...
constructor(...) {
this.createForm();
}
ngOnInit() {
this.carburanti = this.carburantiService.getCarburantiList();
}
createForm() {
this.caricoForm = this.fb.group({
dataCarico: Date,
riferimentoCarico: [''],
dettaglio: this.fb.group({
carburante: '',
quantita: ''
})
});
}
inserisciCarico(carico: Carico) {
this.carichiService.getCarichiList();
this.carichiService.createCarico(this.caricoForm.value);
this.caricoForm.reset();
}
onSubmit() {
}
}
und meine html:
new-carico-form-component.html
<md-card>
<form [formGroup]="caricoForm" novalidate>
<md-card-content>
<md-input-container >
<input mdInput [mdDatepicker]="picker" placeholder="seleziona data" formControlName="dataCarico">
<button mdSuffix [mdDatepickerToggle]="picker" ></button>
</md-input-container>
<md-datepicker #picker></md-datepicker>
<span class="col"> </span>
<md-input-container>
<input mdInput placeholder="riferimento" formControlName="riferimentoCarico">
</md-input-container>
<table formGroupName="dettaglio">
<tr>
<td>
<md-select placeholder="carburante" formControlName="carburante">
...some code...
Das Problem ist, dass ich die Form das einzige, was retten kann, die nicht das Datum nicht funktioniert. Ich habe versucht, in der Konsole vor und nach dem Abonnement zu zeigen und das Datum ist in der Form. irgendwelche Vorschläge? Ich gehe in Firebase zurück und es gibt alles außer dem Datum.