我有:
carico.model.ts
export class Carico {
$key: string;
dataCarico: Date;
riferimentoCarico: string;
dettaglio:{
carburante: string;
quantita: string;
}
}
在我的服务中:
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))
}
}
在我的表单组件中:
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() {
}
}
和我的 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...
问题是我可以保存表单唯一不起作用的是日期。我尝试在订阅前后显示在控制台中,日期在表格中。有什么建议么?我回到 Firebase,除了日期之外什么都没有。