Ionic2/Cordova typescript 项目中的 Moment.js 插件 [英] Moment.js plugins in Ionic2/Cordova typescript project
问题描述
在我用 Typescript 编写的 Ionic 2 项目中,我使用了 moment.js 库.我使用代码片段导入它:
In my Ionic 2 project written in Typescript I use moment.js library. I import it using code snippet:
import * as moment from 'moment';
这样做后,在我的组件中我可以正常使用moment,即:
After I do so, in my component I can use moment normally, ie:
let endDate = moment(data.endDate);
但是,现在我想使用一个专用于 moment.js 的插件——来自这个 repo 的 moment-weekday-calc:https://github.com/andruhon/moment-weekday-calc
however, now I want to use one of plugins dedicated to moment.js - moment-weekday-calc from this repo: https://github.com/andruhon/moment-weekday-calc
我已经通过 npm 安装了插件,但我无法让它运行.我试过了:
I've installed plugin via npm, but I am not able to make it running. I've tried:
import * as moment from 'moment';
import 'moment-weekday-calc';
//(...) - 我的组件代码在这里
//(...) - my component's code here
let test = moment().isoWeekdayCalc({
rangeStart: '1 Apr 2015',
rangeEnd: '31 Mar 2016',
weekdays: [1,2,3,4,5],
exclusions: ['6 Apr 2015','7 Apr 2015'],
inclusions: ['10 Apr 2015']
}); //260
以上代码抛出错误:
Typescript Error
Property 'isoWeekdayCalc' does not exist on type 'Moment'.
知道如何在我的 ionic/cordova 的 typescript 应用程序中使用这个插件吗?
any idea how can I use this plugin in my typescript app for ionic/cordova?
推荐答案
由于该错误只是 typescript 抱怨 isoWeekdayCalc
未在 moment
的类型定义中定义,您可以像这样将其转换为 any
:
Since that error is just typescript complaining about isoWeekdayCalc
not being defined in the type definition of moment
, you can just cast it to any
like this:
let test = (<any>moment()).isoWeekdayCalc({
rangeStart: '1 Apr 2015',
rangeEnd: '31 Mar 2016',
weekdays: [1,2,3,4,5],
exclusions: ['6 Apr 2015','7 Apr 2015'],
inclusions: ['10 Apr 2015']
}); //260
这篇关于Ionic2/Cordova typescript 项目中的 Moment.js 插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!