Endjin - Home

Avoid circular dependencies with AngularJS Directives

by Matthew Adams


A problem you may encounter if you try to implement my previous example in your own code, is that your implementation of templateRepository cannot (apparently) make use of $templateCache, because angular will throw a circular dependency error.

To avoid this, you can inject the $injector service into the templateRepository, and defer the dependency resolution until you make the call.

Something like this:

About the author

Matthew was CTO of a venture-backed technology start-up in the UK & US for 10 years, and is now a Founder of Endjin Ltd, which provides technology strategy, experience and development services to its clients who are seeking to take advantage of Microsoft Azure and the Cloud. You can follow Matthew on twitter.