RequireJS caching objects
Rogerstigers opened this issue · 2 comments
I love the idea you have here and just finished refactoring my code to get a similar pattern working. One big (HUGE) gotcha that took me quite a while to work out, though, was that RequireJS seems to cache any returned object. The result of this is that the creation of the extra property (register) in the app at config time is not persisted to the cached app object. This caused my code to blow up at the registration of the controllers (because register was undefined).
By not returning the app as an object and instead just calling angular.module('myapp').register, I was able to work around it. Just throwing this out there in case anyone else runs across this weirdness (and in case you have some sage advice on the matter).
Ah, something else I wanted to add for posterity. The reason you have to use the register mechanism (as defined in the app's config method) is because by default calling the controller method off of the app injects the controller, but it is not actually resolved by the time the controller is needed (even though the promise is completed). By calling the controller method directly, it seems to bypass the asynch injection.
Great info - thanks Chris.