Posts

Showing posts from 2018

AngularJS Dynamic Templates – Yes We Can! Remote Template Edition

The Goal This is the sequel to my  AngularJS Dynamic Templates – Yes We Can!  post which, to my surprise, has received a fair amount of attention. The number one question I get regarding that post is “This is great! But! How can I do this with remote templates?” and so I wanted to finally address that question with a way to compile dynamic templates using remote resources. I also updated the repository to AngularJS 1.3 as it was originally built on AngularJS 1.0.1! Yikes! Welcome to the future! Before we get started, I want to make it clear that there are a few other ways to do this such as using  ng-switch ,  ng-if , etc. I think that is fine if you have a few templates but if would turn into a DOM nightmare if you had to dynamically render like 40 templates. Also, using $compile to cook your AngularJS templates is pretty low level and so it gives you the ability to dynamically compose some pretty interesting layouts. For instance, you could dynamically pull a...