是否有可能/合理使用像dust.js或外部的模板引擎任何其他与anjularjs? [英] Is it possible / sensible to use external templating engine like dust.js or any other with anjularjs?

查看:232
本文介绍了是否有可能/合理使用像dust.js或外部的模板引擎任何其他与anjularjs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个冲动,用dust.js模板,因为它通过缓存模板提供了UI渲染更好的性能。

I had this urge to use dust.js templates as it provides a much better performance for UI rendering by caching the templates.

但在我的当前项目,我们使用的是angularjs。它甚至可以/合理使用dust.js或角JS ??任何其他模板引擎

But in my current project we are using angularjs. It is even possible/sensible to use dust.js or any other templating engine with angular js ??

即使我使用dust.js我会失去约束力的2路..?

Even if i use dust.js will I lose the 2-way binding .. ?

请建议考虑一个比较大的SPA ..?

Please suggest considering a relatively large SPA.. ?

P.S。我是新手在这两个角和灰尘。

P.S. I am a novice in both angular and dust.

推荐答案

听起来像是不错的用例的过滤器

Sounds like a good use case for a filter!

注意dust.js是的异步的渲染器,但是如果你已加载的一切那么灰尘就会同步触发(<一个href=\"http://stackoverflow.com/questions/9848851/is-it-possible-to-render-dust-js-templates-synchronously#comment20440019_10407693\">most时间的)

Be aware that dust.js is an asynchronous renderer, but if you've already loaded everything then dust will fire synchronously (most of the time)

app.module('yours',[]).filter('dustRender', function(){
  return function(input, templateName){
    var rendered;
    dust.render(templateName, input, function(err, out){
      if('string' === typeof out){
        rendered = out;
      }
      err && console.error('Dust rendering error!', err);
    });
    return rendered || input;
  };
});

模板

<span>{{ modelData | dustRender:'registered-dust-template' }}</span>

注:角 $消毒的输出,如HTML

这篇关于是否有可能/合理使用像dust.js或外部的模板引擎任何其他与anjularjs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆