Thursday, 16 March 2017

Moment.js plugins in Ionic2/Cordova typescript project

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);

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

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

above code throws an error:

Typescript Error
Property 'isoWeekdayCalc' does not exist on type 'Moment'.

any idea how can I use this plugin in my typescript app for ionic/cordova?



via dease

No comments:

Post a Comment