使用Express Handlebars和Angular JS [英] Using Express Handlebars and Angular JS

查看:187
本文介绍了使用Express Handlebars和Angular JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在建立一个使用 NodeJS 为服务器, Express Handlebars (Just Handlebars 但是服务器端),希望 AngularJS 有些客户端的东西。

I am currently building a website that uses NodeJS for the server, Express Handlebars(Just Handlebars but server side) , and hopefully AngularJS for some client side stuff.


AngularJS和Handlebars使用与模板相同的语法

{{foo}}

这会导致一个问题, AngularJS代码首先由Express Handlebars进行解释,然后抛出一个错误,因为它试图拉出的数据只存在于Angular not Node中。

AngularJS and Handlebars use the same syntax for templating
{{foo}}
This causes a problem where AngularJS code will be interpreted by Express Handlebars first, which will then throw an error because the data it is trying to pull only exists in Angular not Node.


有没有办法让AngularJS和Express Handlebars一起工作?

Is there a way to get AngularJS and Express Handlebars to work together?



  • 更改AngularJS


    • 的语法我正在看BackboneJS,看起来可以更改语法。可能有类似的东西是AngularJS。


    • 它只会返回未解析的内容。但是我无法弄清楚如何做到这一点。

    推荐答案

    您的第一个解决方案是可行的,AngularJS允许更改文本插入的开始/结束符号,如下所示:

    Your first solution is possible, AngularJS allow to change the start/end symbols of text interpolation like this:

    appModule.config(function($interpolateProvider) {
      $interpolateProvider.startSymbol('{[{');
      $interpolateProvider.endSymbol('}]}');
    });
    

    然后你可以在你的模板中使用它:

    Then you could use it in your template:

    <div>{[{message}]}</div>
    

    另请参阅: $ interpolateProvider文档

    希望这有帮助。

    这篇关于使用Express Handlebars和Angular JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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