Skip to content Skip to sidebar Skip to footer

Requirejs Dependency Not Working

I am trying to use angular-ladda directive in my app. Here is my main.js which is the requirejs manifesto file: requirejs.config({ paths: { underscore: 'lib/underscore

Solution 1:

I think for the dependency to work, you'd have to define ngLadda declaration as a module

define(function (require) {
    // your ngLadda declaration here
}

Edit: there is another possibility When you look at code of Ladda: https://github.com/hakimel/Ladda/blob/master/js/ladda.js

You see that Ladda is being wrapped in define(){}

// AMD moduleelseif( typeof define === 'function' && define.amd ) {
        define( [ 'spin' ], factory );
    }

In requireJS docs it's stated that:

Only use other "shim" modules as dependencies for shimmed scripts, or AMD libraries that have no dependencies and call define() after they also create a global (like jQuery or lodash). Otherwise, if you use an AMD module as a dependency for a shim config module, after a build, that AMD module may not be evaluated until after the shimmed code in the build executes, and an error will occur. The ultimate fix is to upgrade all the shimmed code to have optional AMD define() calls.

http://requirejs.org/docs/api.html#config-shim

So, Ladda is an AMD module with deps already defined. In your main.js put it outside of shim:

'ladda': {
     exports: 'Ladda'
 },
'ngLadda': {
     deps: ['ladda']
 }
 shim: {
    //your other shimmed modules
 }

Put your ngLadda in define(function(require){}) like it's said in original answer, but don't put any dependencies inside.

Post a Comment for "Requirejs Dependency Not Working"