I am working on ionic2
project. I have just start using moment.js
but I have a weird issue. I have installed in via npm: npm install moment -S
.
Then I have used it in my code:
import moment from 'moment' ... let x = moment() debugger
On the console I get this funny issue:
> x < Moment {_isAMomentObject: true, _isUTC: false, _pf: {…}, _locale: Locale, _d: Wed Jun 27 2018 12:06:23, …} > y = moment() < VM770:1 Uncaught ReferenceError: moment is not defined at eval (eval at Phase (phase.ts:13), <anonymous>:1:1) at new Phase (phase.ts:13) at new Stage (stage.ts:10) at new HomePage (home.ts:39) at createClass (core.es5.js:10795) at createDirectiveInstance (core.es5.js:10621) at createViewNodes (core.es5.js:11971) at createRootView (core.es5.js:11876) at callWithDebugContext (core.es5.js:13007) at Object.debugCreateRootView [as createRootView] (core.es5.js:12468)
Why can't I work with moment within the console?
Open Chrome, press Ctrl+Shift+j and it opens the JavaScript console where you can write and test your code.
To open the developer console in Google Chrome, open the Chrome Menu in the upper-right-hand corner of the browser window and select More Tools > Developer Tools. You can also use Option + ⌘ + J (on macOS), or Shift + CTRL + J (on Windows/Linux).
Could fetch it from browser console like this:
fetch('https://momentjs.com/downloads/moment.min.js') .then(response => response.text()) .then(text => eval(text))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With