I’m trying to add a date selecting function into my app but when I click the “add” button, the date doesn’t get saved into my Firebase database.
Here is the code html code:
<ion-item>
<ion-label>Date</ion-label>
<ion-datetime displayFormat="DD MMM" [(ngModel)] = "item.date">
</ion-datetime>
</ion-item>
My item.model.ts code
export interface Item{
key?: string;
date?: string;
}
And my ts code
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Item } from '../../models/item/item.model';
import { DutiesList } from '../../services/duties/duties.services';
import { Observable } from 'rxjs/Observable';
import { ToastService } from '../../services/toast/toast.service';
@IonicPage()
@Component({
selector: 'page-add',
templateUrl: 'add.html',
})
export class AddPage {
private myDate: string;
viewDuty$: Observable<Item[]>
item: Item = {
date: '',
}
constructor(public navCtrl: NavController,
public navParams: NavParams,
private addDuty: DutiesList,
private toast: ToastService) {}
ionViewDidLoad() {
console.log('ionViewDidLoad AddPage');
}
addItem(item: Item){
this.addDuty.addItem(item).then(ref =>{
this.toast.show('Duty added!');
});
console.log.length;
}
}