最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can i use another template engine with angularjs? - Stack Overflow

programmeradmin3浏览0评论

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.

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.

Share Improve this question asked Jul 27, 2013 at 3:25 Taleb ElemTaleb Elem 1191 silver badge6 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 8

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 remend to do so

发布评论

评论列表(0)

  1. 暂无评论