Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i use another template engine with angularjs?

Can i use another template engine with Angular? i googled it and most of it just refer to the current template engine used by angular, i need a template engine with simple logic like "if", "or" .. thank you.

like image 451
Taleb Elem Avatar asked Jul 27 '13 03:07

Taleb Elem


3 Answers

Angular doesn't have a template engine replacement, mostly because there isn't a template engine like in other frameworks (ie. Backbone.js). In Angular, there is string interpolation ({{expression}}) but no templates.

I'd first point you to the ngIf directive, where you can conditionally include DOM elements:

<div ng-if="somethingIsTrue">TRUE</div>
<div ng-if="!somethingIsTrue">FALSE</div>

If that's not enough, consider your template engine of choice to pre-process your HTML. You can set up a grunt task to turn template files into HTML files that Angular can then reference.

like image 192
Brian Genisio Avatar answered Oct 31 '22 06:10

Brian Genisio


Brian mentioned ng-if, ng-switch could possibly also serve your needs:

<div ng-switch on="selection">
    <div ng-switch-when="settings">Settings Div</div>
    <span ng-switch-when="home">Home Span</span>
    <span ng-switch-default>default</span>
</div>

This will switch on the value of selection with the values specified in ng-switch-when and use ng-switch-default as the default case.

Documentation

like image 43
sushain97 Avatar answered Oct 31 '22 06:10

sushain97


You can probably rewrite $interpolateProvider, but don't recommend to do so

like image 27
Stepan Suvorov Avatar answered Oct 31 '22 07:10

Stepan Suvorov