2017-01-14 82 views
0

设定值我使用离子2.1.18与angularjs 2 RC4和我有一个问题集小时离子2/angularjs 2离子日期时间无法在小时

booking.html

<ion-item> 
    <ion-label>Start Date</ion-label> 
    <ion-datetime displayFormat="DD MMM YYYY" [(ngModel)]="startDate" min="{{thisYear}}" max="{{nextYearWithLastDay}}"></ion-datetime> 
</ion-item> 

<ion-item> 
    <ion-label>Start Time (Hour)</ion-label> 
    <ion-datetime displayFormat="HH00" [(ngModel)]="startTime" pickerFormat="HH"></ion-datetime> 
</ion-item> 

booking.ts

import { Component } from '@angular/core'; 
import { NavController, NavParams } from 'ionic-angular'; 

@Component({ 
    selector: 'page-booking', 
    templateUrl: 'booking.html' 
}) 
export class Booking { 

    constructor(public navCtrl: NavController, public navParams: NavParams) {} 

    now: Date = new Date(); 
    thisYear : Number = this.now.getFullYear(); 
    nextYearWithLastDay : String = (this.now.getFullYear() + 1) + "-12-31"; 

    startDate: String = this.now.toISOString(); 
    endDate: String = this.now.toISOString(); 

    startTime: Number = this.now.getHours(); 
    endTime: Number = this.now.getHours(); 

    ionViewDidLoad() { 

    console.log('ionViewDidLoad Booking'); 

    } 

} 

的startDate能够设置为当前日期,但开始时间无法设置,尽管我ALRE安以轩定义在类

enter image description here

回答

-1

我没有测试,但设置你的时间是这样的:

startTime = this.now.getHours()+':'+ this.now.getMinutes(); 
displayFormat="HH:00" 
+0

要设置字符串编号和确认失败! –

+0

对不起,我只是复制你的代码。看到这个[链接](https://github.com/driftyco/ionic-preview-app/blob/master/src/pages/datetime/basic/pages.ts)。我也编辑答案。 –

相关问题