angular - 安装 ionic 2 日期选择器

标签 angular ionic-framework ionic2

我对 ionic 2 中的日期时间选择器有一些疑问:

<强>1。我选择它时存储日期时间的变量是什么? 我从我的项目中添加我的代码,我只是尝试将它存储在一些变量中但没有成功

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import {DatePicker} from 'ionic-native';
import {Calendar} from 'ionic-native';
import {Platform} from 'ionic-angular';
import { Pipe } from '@angular/core';



/*
  Generated class for the InviteDates page.

  See http://ionicframework.com/docs/v2/components/#navigation for more info on
  Ionic pages and navigation.
*/
@Component({
  selector: 'page-invite-dates',
  templateUrl: 'invite-dates.html'
})
export class InviteDates {
  dateshow:any;
  newdate:any;
  d:any;
  b:any;
  year:any;
  month:any;
  day:any;
  today:Date;
  mydate: String = new Date().toISOString();


    constructor(public navCtrl: NavController,private platform:Platform) {
    this.d="";

  }

  ionViewDidLoad() {
    console.log('Hello InviteDates Page');
    this.datefun();
  }

}

html文件

    <ion-content padding>

    <ion-item>
        <ion-label>Date</ion-label>
        <ion-datetime displayFormat="DD/MM/YYYY" [(ngModel)]="mydate"></ion-datetime>
        <p> the date is :{{mydate}}</p>


    </ion-item>
</ion-content>

在我的控制台中,我收到这条消息“datetime object”,所以我想声明 datetime 变量,但它显示错误 enter image description here

2.我想要 3datetime: - #1 当前日期的日期时间 - #2 所选日期的日期时间 - #3 用户选择时间的日期时间 怎么做?

3.如何限制日期?我的意思是,用户无法选择过去,例如从今天开始的一周。

最佳答案

这是我认为您想要实现的目标的最佳表示(格式和样式有限):

组件:

    @Component({
      selector: 'page-invite-dates',
      templateUrl: 'invite-dates.html'
    })
    export class HomePage {
      date1: string = new Date().toDateString();
      date2: string;

      min: string = '';
      max: string = '';

      constructor() {
        let today = new Date();
        let oneWeek = new Date();

        oneWeek.setDate(oneWeek.getDate() + 7);

        this.min = today.toISOString();
        this.max = oneWeek.toISOString();
      }
    }

查看:

<ion-content>
  <ion-item>
    {{date1}}
  </ion-item>
  <ion-item>
    <ion-label>Date</ion-label>
    <ion-datetime min="{{min}}" max="{{max}}" displayFormat="MM/DD/YYYY" [(ngModel)]="date2"></ion-datetime>
  </ion-item>
  <ion-item>
    {{date2}}
  </ion-item>
</ion-content>

有关 ionic-datepicker ( http://ionicframework.com/docs/v2/api/components/datetime/DateTime/ ) 的更多详细信息,请参阅 API

随意寻找为 Angular 2 构建的第 3 方组件

关于angular - 安装 ionic 2 日期选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39885067/

相关文章:

javascript - 如何使用复杂的 json 嵌套属性

angular - 在 .ts 文件中使用 ngx-translate

node.js - 无法加载资源: the server responded with a status of 404 (Not Found) - Ionic2

ios - ITMS-90809:不推荐使用的API使用错误苹果将停止接受使用UIWebView API的应用程序的提交。

events - 退订页面更改事件

android - 旧货如何消费

css - Angular MdSelect 没有下划线未定义

angular - 触发并忘记 Angular 4 http post 请求

css - ionic : is there any way to enlarge the text input field?

javascript - Angular UI 路由器在更改状态时不执行 Controller 代码