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.
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.
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
You can probably rewrite $interpolateProvider, but don't recommend to do so
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With