2

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

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 ??

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

Please suggest considering a relatively large SPA.. ?

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

4

1 回答 1

1

听起来像是一个很好的过滤器用例!

请注意,dust.js 是一个异步渲染器,但是如果您已经加载了所有内容,那么灰尘将同步触发(大部分时间

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>

注意:Angular $sanitize的输出,如 html。

于 2014-02-06T02:10:24.267 回答