0

I am trying to get experience with angular by making an app (for my own use) and I ran into an issue.

I decided to try to implement lazy loading (like in the "Complex" part of the answer to this question ) and had that working with my own additions to it.

I wanted to make components more self-contained though and decided to try to make a directive to load any javascript dependencies for me.

This left me with the following template html

<div dependencies="app/components/home/controller.js" ng-controller="HomeCtrl as home">
    This is the home page.<br />
    {{home.test}}
</div>

When I try to load this page I see the following error

Argument 'HomeCtrl' is not a function, got undefined

If I remove the ng-controller directive then my directive works fine and controller.js is loaded.

Based on the source for ngController I thought that setting the priority for my directive higher than 500 would work but it didnt seem to help.

I also tried moving my directives contents from link to compile.pre. It didnt help either, my directives compile runs before the error but compile.pre does not.

Is there any way to make my directive load/run first, before ngController?

Community
  • 1
  • 1
Marie
  • 2,114
  • 1
  • 17
  • 31
  • Have you seen this thread - http://stackoverflow.com/questions/29468522/angular-controller-not-loading-using-oclazyload-and-ngroute. Might help. Why not use something like 'requireJs' or '$ocLazyLoad' for your purpose? One more thing which maybe worth a try - remove the ng-controller and move it to the $routeProvider handler ( or state handler ) for that view? – FrailWords Nov 06 '15 at 20:55
  • I am just doing this for the experience; I did see that thread but it doesn't really help. I looked into those a little but the way I am using works so and it isnt too complicated. I did have the controller in the routeProvider but I wanted to simplify my routes and it seemed like controller would be better off in the relevant template anyways. I thought it would be a good introduction into making a directive then i ran into this issue. – Marie Nov 06 '15 at 22:49
  • I get your point. Would be interesting to see a solution in your way. – FrailWords Nov 07 '15 at 07:32

0 Answers0