A
A
Artem Shchurin2015-06-06 10:06:29
JavaScript
Artem Shchurin, 2015-06-06 10:06:29

Why can't pass app.js as a module dependency(requireJS)?

Hello!
My application is in angularJS, the dependencies are described in requireJS, it was not written by me, I just received it a few days ago and said understand it
. I want to create a directive for the main application module, aka app.js
The app.js module is already connected to requireJS, the path to it paths, application controllers freely use app.js as a dependency, but I get undefined when I call a directive on a module.
Directive code:

define(['app'], function(app) {
  app.directive('focus', function() {
    return {
      link: function($scope, element, attrs){
        console.log('test')
      }
    }
  });
});

require config:
paths: {
            app: '../app/app',
         
            ...

            settingsCtrl: '../app/trend/settings/settings',
            
            ...

            focus: '../common/directives/focus/focus',
            
        },

settingsCtrl painlessly uses app.js as a dependency
why doesn't the focus directive get a reference to app.js

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2015-06-06
@romteh

you may need to write dependencies:

shim: {
    	'app' : {
    		deps: ['focus']
    	}
}

maybe when you call:
app.directive('focus'...
focus hasn't been loaded yet

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question