-
Notifications
You must be signed in to change notification settings - Fork 397
Issue using angular-moment and requirejs #36
Comments
The same thing - I have to add moment.js manually right before require.js to make it works |
Guys, thank you for the feedback. Perhaps you can provide a short jsfiddle / plunkr example showing how you currently use require.js and moment in your angular application? Thanks! |
I figured out how to fix it by using oficial advice from Moment.js website http://momentjs.com/docs/#/use-it/require-js/ You can define custom module called moment.js (or whatever) with code define(["moment"], function (moment) {
moment.lang('ru');
moment().format();
return moment;
}); and load it together with moment.js plugin in paths section of require.config "momentjs": "../lib/momentjs/moment",
"moment": "modules/moment", // this is your custom module
"angular-moment": "../lib/angular-moment/angular-moment" Also don't forget to write them in shim section as well "momentjs": {
"deps": ["jquery"]
},
"moment": {
"deps": ["momentjs"]
},
"angular-moment": {
"deps": ["angular", "momentjs"]
} And finally load this stuff in define require("momentjs");
require("moment");
require("angular-moment"); |
@AlexMoreStains Please have a look at 46f1a24, does the solution there work for you? Thanks guys :-) |
Hello, Here is an example of this case http://plnkr.co/edit/C9rEBk This fix will work great if we load it using requirejs like @AlexMoreStains says before. I think the module angularMoment should be created anytime but this cannot be done if we load angular using require... maybe there is no fix for that and we just have to be aware to load all third party script before requirejs |
@antho1404 The issue here is that when you include require.js, the moment.js library sees it and does not register the global |
I close the issue for now. If there is any issues with the implementation, please explain and re-open. |
I just came across a similar issue myself, possibly the second one @antho1404 came across. The problem I had was that the module is defined with the explicit name: Here's my working require config for anyone else who comes across this problem: require.config({
paths: {
angular: "../bower_components/angular/angular",
angularRoute: "../bower_components/angular-route/angular-route",
angularMocks: "../bower_components/angular-mocks/angular-mocks",
moment: "../bower_components/moment/moment",
"angular-moment": "../bower_components/angular-moment/angular-moment",
gantt: "../bower_components/angular-gantt/assets/angular-gantt"
},
shim: {
angular: { exports: "angular" },
angularRoute: ["angular"],
angularMocks: ["angular"],
gantt: ["angular-moment"]
}
}); |
I encounter the same issue, If you have the same trouble, please change the declare name to "angular-moment". like "angular-moment": "../bower_components/angular-moment/angular-moment", |
Following up on @WilliamCarter 's solution: it works. |
Thanks @WilliamCarter, this worked for me as well. |
@WilliamCarter, seems like you have nailed it. Can you please send a pull request with the suggested change? |
I'm having this problem as well... |
@WilliamCarter thanks for the solution.
to
|
In my case nothing is working Mu requre file is this require.config({
}); require(['app-start']); and app start file is this define(['app-route', 'jquery', 'jqueryui', 'moment', 'angular-moment', 'bootstrap', 'selectBoxIt', 'factory', 'projectViewDir', 'constants', 'filter', 'login', 'dashboard', 'projectView'], function (router, jquery, jqueryui, moment,angularMoment, bootstrap, selectBoxIt, factory, projectViewDir, constants, filter, loginModu, dashboardModu, project) {
}); Please anyone help me on this |
Because momentjs lib can check if the define function (from requirejs) exists and in this case create a module for requirejs, the moment variable is not global and so cannot be accessible using $window.moment so this create some execution errors.
One fix actually is to load requirejs after momentjs but I think this should be fix
momentjs: v2.5.1
angular-moment: v0.6.2
The text was updated successfully, but these errors were encountered: