Go to reference on angular 1


#1

Hi, I have created this ‘./tern-project’ file on the root of my angular 1 project:

{
  "libs": [
    "browser"
  ],
  "loadEagerly": [
    "public/app/**/*.js"
  ],
  "dontLoad": [
    "node_modules/**"
  ],
  "plugins": {
    "node": {},
    "es_modules": {}
  }
}

My problem is that ternjs can’t find the definition. For example:

angular.module("controllers")
  .controller('applicantGetController', ['config', 'User', 'Applicant', 'Mentor', 'Issue', 'Event', 'City', 'Auth', 'AuthRedirect', '$location', '$controller', 'flash', function (config, User, Applicant, Mentor, Issue, Event, City, Auth, AuthRedirect, $location, $controller, flash) {
    var vm = this;
    ...

ternjs can’t find the definition of config, User, Mentor, etc.

In my angular project this files are imported on the main index.html. I think that with loadEagerly configured ternjs can find the definitions. How I can solve this?

Thanks!


#2

Have you tried the angular plugin?


#3

Hi @marijn I have try the angular plugin by adding “angular” into this .tern-project file:

{
  "libs": [
    "browser"
  ],
  "loadEagerly": [],
  "dontLoad": [],
  "plugins": {
    "node": {},
    "es_modules": {},
    "angular": {}
  }
}

But ternjs can’t find the dependence, now with TernDefPreview open the same file.

Regards.


#4

I experienced something like this.

I resolved the problem by, for each angular module in my project, storing the result of the original call to angular.module() creating that module, and then using this saved reference rather than calling angular.module() again. So for each angular module in my project there is only a single call to angular.module().

The method angular.module() serves dual purposes - the first time you call it you add a second parameter specifying module dependencies and then subsequently you call it with a single parameter which simply retrieves the previously created module. I am not 100% sure of what is going on, but I think because of the way Tern loads the files it can get this order backwards, so that it treats the “controllers” module as not having any specified dependency on any other module. Presumably the OP had User, Mentor etc defined in a module other than “controllers”.