[web 前端] angular4之angular-io-datepicker

angular-io-datepicker是一款非常漂亮的时间组件,git地址 https://www.npmjs.com/package/angular-io-datepicker

可以直接通过指令使用,指令属性如下

property type default description
mode string date Changes view mode - date, datetime, time
disabled boolean false Disables controls
showClearButton boolean true Show or not clear input button
format string defaultFormat = {"date": "LL","datetime": "LLL","time": "LT"}; Changes view format that provides moment
mode: ui展示方式,可以根据  date, datetime, time 是否展示年月日,时分秒

disabled: 警用属性

format: 时间展示方式,依赖了另外一个非常好用的时间组件 moment(http://momentjs.com/)


monent提供为时间操作提供了非常简便的方法,和java的joda_time.jar一样,非常好用

Format Dates

moment().format('MMMM Do YYYY, h:mm:ss a'); // August 30th 2017, 10:15:33 am
moment().format('dddd');                    // Wednesday
moment().format("MMM Do YY");               // Aug 30th 17
moment().format('YYYY [escaped] YYYY');     // 2017 escaped 2017
moment().format();                          // 2017-08-30T10:15:33+08:00

Calendar Time

moment().subtract(10, 'days').calendar(); // 08/20/2017
moment().subtract(6, 'days').calendar();  // Last Thursday at 10:18 AM
moment().subtract(3, 'days').calendar();  // Last Sunday at 10:18 AM
moment().subtract(1, 'days').calendar();  // Yesterday at 10:18 AM
moment().calendar();                      // Today at 10:18 AM
moment().add(1, 'days').calendar();       // Tomorrow at 10:18 AM
moment().add(3, 'days').calendar();       // Saturday at 10:18 AM
moment().add(10, 'days').calendar();     

使用angular-io-datepicker步骤说明

第一步安装:npm i angular-io-datepicker --save

第二步:导入DatePickerModule in you AppModel

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    FormsModule,
    ReactiveFormModule,
    OverlayModule,
    DatePickerModule,
    ...
  ],
  providers: [],
  bootstrap: [AppComponent]
})
 
export class AppModule {
}

备注: 这里的ReactiveFormModule是可选的,看你再使用组件是否使用的form 是模板驱动(Template-Driven Form) 还是模型驱动 Model-Driven Form,

html使用组件

<form #form="ngForm">
    <date-picker ngModel name="date"></date-picker>
</form>


结果ok

           


遗漏问题:

在使用 ng build --prod 时会编译失败

ERROR in Error encountered resolving symbol values statically. Calling function 'ControlValueAccessorProviderFactory', function calls are not supported. Consi
der replacing the function or lambda with a reference to an exported function, resolving symbol DatePicker in D:/myapp/node_modules/angular-i
o-datepicker/src/datepicker/datePicker.d.ts, resolving symbol DatePicker in D:/myapp/node_modules/angular-io-datepicker/src/datepicker/datePi
cker.d.ts
ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'D:\myapp\src'
 @ ./src/main.ts 4:0-74
 @ multi ./src/main.ts
https://github.com/rd-dev-ukraine/angular-io-datepicker/issues/12

请大家先编译看下这个问题解决之后在使用,目前成熟的时间组件 ng2-datetime 整合 bootstrap

使用aot编译是没有问题的:  ng build --prod --aot=false


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

源14

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值