I want my date and time to automatically display the current date and time without needing to click the picker first.
The output I want is as below:
As above, I want my app to directly take the current date and time without the need of user to click the picker first.
All this while my current app uses the default code from ionic documentation where the user need to click the picker to see and choose current date or time like below:
My current html code is as follows:
<ion-list>
<ion-list-header>
<ion-label>
Tarikh & Masa Kesalahan:
</ion-label>
</ion-list-header>
<ion-card>
<ion-item>
<ion-datetime dateFormat="MM/DD/YYYY" placeholder="MM/DD/YYYY" [(ngModel)]="form.tarikh_pemeriksaan"></ion-datetime>
<ion-icon name="calendar" slot="end"></ion-icon>
</ion-item>
</ion-card>
<ion-card>
<ion-item>
<ion-datetime display-format="h:mm A" picker-format="h:mm A" value="1990-02-19T07:43Z" placeholder="--:-- --" [(ngModel)]="form.masa"></ion-datetime>
<ion-icon name="time" slot="end"></ion-icon>
</ion-item>
</ion-card>
</ion-list>
My typescript code is as below:
export class FcPage implements OnInit {
form: any = {}
premis: any = {};
negeri: any;
negeripenerima:any;
daerah: any;
daerahpenerima: any;
daerahpenggerak: any;
daerahindividu: any;
loading: boolean;
service: any;
userdetail: any = {}
perundangan: any = {};
kesalahan: any = {};
senarai_kesalahan: any = {};
peraturan: any = {}
projek: any = {};
jpunca: any = {};
checked : boolean = false;
constructor(
public api: ApiService,
public modalController: ModalController,
public router: Router,
private userData: UserData,
) {
this.form = {}
this.form.showCetak = false;
this.senarai_kesalahan = JSON.parse(localStorage.getItem('jas_item_kesalahan'));
//this.form.tarikh_pemeriksaan = new Date().toJSON().split('T')[0];
this.form.tarikh_pemeriksaan = this.form.masa = new Date().toISOString();
}
ngOnInit() {
this.getNegeri();
this.getNegeriPenerima();
this.getDaerah();
this.getDaerahPenerima();
this.getDaerahIndividu();
this.getDaerahAll();
this.getJenisPunca();
this.getUserDetail();
this.getUsermisc();
this.senarai_kesalahan = JSON.parse(localStorage.getItem('jas_item_kesalahan'));
}


