jsFiddle Example: Mustache Directive for AngularJS

In the blog post Considering Speed and Slowness in AngularJS, the idea is put forward to use MustacheJS, wrapped in an AngularJS Directive to render dynamic content, but come away with no or minimal bindings. I liked the idea, but I found the application too specific; while I get the philosophy of making Directives specific usage, I also hate redundant tools and making a separate directive for each and every place I want to use a Mustache template seems terrible too.

The key detail to note in this example is that the first element wrapped by my directive is a div with a ng-non-bindable on it. That is necessary to keep AngularJS from trying to parse and bind your Mustache template code.

 
Comments are not allowed for this entry.
Jon Hartmann, July 2011

I'm Jon Hartmann and I'm a Javascript fanatic, UX/UI evangelist and former ColdFusion master. I blog about mysterious error messages, user interface design questions, and all things baffling and irksome about programming for the web.

Learn more about me on LinkedIn.