Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular 1.4.x with ocLazyLoad 1.0.4 fails to load controller. #221

Closed
dgwaldo opened this issue Aug 4, 2015 · 12 comments
Closed

Angular 1.4.x with ocLazyLoad 1.0.4 fails to load controller. #221

dgwaldo opened this issue Aug 4, 2015 · 12 comments

Comments

@dgwaldo
Copy link

dgwaldo commented Aug 4, 2015

Seems like there may be a regression from 1.0.3 to 1.0.4. The following code works in 1.0.3 and fails in 1.0.4. The error generated is...

Error: [ng:areq] Argument 'sftSearchController' is not a function, got undefined
http://errors.angularjs.org/1.4.2/ng/areq?p0=sftSearchController&p1=not%20aNaNunction%2C%20got%20undefined
at REGEX_STRING_REGEXP (http://cdn.jsdelivr.net/angularjs/1.4.2/angular.js:68:12)
at assertArg (http://cdn.jsdelivr.net/angularjs/1.4.2/angular.js:1770:11)
at assertArgFn (http://cdn.jsdelivr.net/angularjs/1.4.2/angular.js:1780:3)
at http://cdn.jsdelivr.net/angularjs/1.4.2/angular.js:8977:9
at compile (webpack:///.//angular-ui-router/release/angular-ui-router.js?:4018:28)
at invokeLinkFn (http://cdn.jsdelivr.net/angularjs/1.4.2/angular.js:8652:9)
at nodeLinkFn (http://cdn.jsdelivr.net/angularjs/1.4.2/angular.js:8152:11)
at compositeLinkFn (http://cdn.jsdelivr.net/angularjs/1.4.2/angular.js:7543:13)
at publicLinkFn (http://cdn.jsdelivr.net/angularjs/1.4.2/angular.js:7418:30)
at updateView (webpack:///./
/angular-ui-router/release/angular-ui-router.js?:3959:23)

.config({
  'sft': {
    abstract: true,
    controller: 'sftAppController',
    templateUrl: 'src/app/views/app.html'
  },
  'sft.search': {
    url: '/search',
    templateUrl: 'src/app/views/page.html',
    controller : 'sftSearchController',
    data: {
      index: APP_DATA.site.hasElasticSearch,
      follow: APP_DATA.site.hasElasticSearch
    },
    resolve: {
      searchBundle: ['$q', '$ocLazyLoad', function($q, $ocLazyLoad) {
          var deferred = $q.defer();
          require.ensure(['../searchApp.js'], function(require) {
            var mod = require('../searchApp.js');
            $ocLazyLoad.load({
                  name: 'ari.endvr.sft.app.search'
              });
              deferred.resolve(mod.controller);
          }, 'searchBundle');
          return deferred.promise;
    }]
  }
},
'sft.search.list': {
  url: '/:type',
  template: '<div ui-view></div>'     
},
'sft.search.list.recommended': {
  url: '/recommended/{params:RawValue}',
  recommended: true,
  controller: 'sftSearchListController',
  templateUrl: 'src/widgets/search/views/lists/recommended.html'
},
'sft.search.list.studio': {
  url: '/studio/{params:RawValue}',
  studio: true,
  controller: 'sftSearchListController',
  templateUrl: 'src/widgets/search/views/lists/default.html'
},
'sft.search.list.default': {
  url: '/{params:RawValue}',
  controller: 'sftSearchListController',
  templateUrl: 'src/widgets/search/views/lists/default.html'
},
@scottmcnab
Copy link

I also observe modules not loading with ocLazyLoad 1.0.4 that work fine in 1.0.3. In my case, I'm attempting to $ocLazyLoad.load() a module loaded from webpack. For some reason, it does not invoke the module.config() or module.run() blocks, nor seem to register the module correctly.

Note: if I instead call $ocLazyLoad.inject() to initialise the webpack-loaded module, it DOES call the run() block, however the module's dependencies are NOT loaded.

Reverting to 1.0.3 causes $ocLazyLoad.load() to work again, however with 1.0.3 for some reason the module.run() method is not called, while the module.config() is. (I'm using Angular 1.4.3)

@maxwarch
Copy link

Hello, I tried the solution of @scottmcnab and it works.
Weird !

@kresli
Copy link

kresli commented Aug 19, 2015

revert to 1.0.1 version will bring back run initialising.

@redders6600
Copy link

To add to this, I had to revert to v0.5.1 after recently updating to 1.0.4.

To be honest, I don't understand a lot about this, so I'll just explain the behaviour:

  • module.a contains directiveA
  • directiveA has a dependency on serviceB
  • module.b. contains serviceB
  • module.a is defined with a dependency on module.a:
    • angular.module('module.a', [ 'other.modules', 'module.b' ])
  • module.a is explicitly loaded using $ocLazyLoad
  • HTML containing directiveA is compiled once the load promise for module.a is resolved.

With versions after 1.0.0, I found that there were situations where directiveA would throw errors saying it's missing serviceBprovider.

Sorry if this is not helpful, I might be able to produce a plunkr for it at a later date.

@srolel
Copy link

srolel commented Aug 22, 2015

+1, not working after upgrading from 1.0.1 to 1.0.4

@ocombe ocombe added the bug label Aug 23, 2015
@ocombe
Copy link
Owner

ocombe commented Aug 23, 2015

Sorry for the long time without any answer to this, I was away for 3 weeks...
@dgwaldo could you make me a plunkr? Or just narrow the bug to a simple example? It's hard to see what is failing here :)

@rockallite
Copy link

Exactly the same error as @dgwaldo (Argument 'SomeController' is not a function, got undefined), using ocLazyLoad v1.0.4, except that I'm using AngularJS v1.3.16. Revert back to ocLazyLoad v1.0.3 resolve the problem immediately, and the controllers of the lazy module loads fine.

@aberenyi
Copy link

+1.
Easy way to reproduce

  1. git clone https://github.com/ay13/webpack-angular-oclazyload.git - sidenote: this repo is mentioned in the docs too - IMHO it could be potentially misleading as it works out-of-the-box (0.6.3), but does not after upgrading to the latest version (or 1.0.4).
  2. npm run dev - check Page 4 - should be okay. ctrl+c to exit.
  3. (optional) npm install oclazyload@1.0.3
  4. (optional) npm run dev - check Page 4 - should be still okay. ctrl+c to exit.
  5. npm install oclazyload@1.0.4 or simply npm install oclazyload@^1 to install the latest version (1.0.5)
  6. npm run dev - check Page 4 - should say: Error: [ng:areq] Argument 'Page4Controller' is not a function, got undefined

@ocombe
Copy link
Owner

ocombe commented Sep 28, 2015

Ahh thanks for the test case! Should help a lot :)

@aberenyi
Copy link

No worries - keep up the good work 🍻

@ocombe ocombe closed this as completed in 953584e Oct 1, 2015
ocombe added a commit that referenced this issue Oct 1, 2015
fix: calling inject from loaders should pass the "real" module param
Fixes #221
@ocombe
Copy link
Owner

ocombe commented Oct 1, 2015

Ok it should be fixed in 1.0.6, thank you a lot @phenomnomnominal for the PR & @aberenyi for the test case!

@aberenyi
Copy link

aberenyi commented Oct 1, 2015

👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants