Ionic2 / Cordova打字稿项目中的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';
在我这样做之后,在我的组件中我可以正常使用,即:
After I do so, in my component I can use moment normally, ie:
let endDate = moment(data.endDate);
但是,现在我想使用一个专用于moment.js的插件 - 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'.
任何想法如何在我的typescript应用程序中使用此插件来进行离子/ cordova?
any idea how can I use this plugin in my typescript app for ionic/cordova?
推荐答案
由于该错误只是抱怨 isoWeekdayCalc
的打字稿未在类型定义中定义时刻
,您可以将它转换为任何
,如下所示:
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打字稿项目中的Moment.js插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!