Home  >  Q&A  >  body text

angular.js - Beego 与 AngularJS的模板格式冲突,该怎么解决?

我在 HTML 里使用了 ·angularjs· 的模板,但是在beego的 Controller 中,我设置

this.TplNames = "index.html"

但是运行之后服务器端报出的信息如下图:

我猜测是因为 beego 用 Go 自己的模板解析了,所以找不到变量。但是我把autorender=false也设置了之后,还是会显示这个错误,而且前端也收不到index.html的内容了。

漂亮男人漂亮男人2737 days ago1012

reply all(5)I'll reply

  • 滿天的星座

    滿天的星座2017-05-15 16:51:08

    https://github.com/astaxie/beego/issues/297 This has been answered by the author.

    beego.TemplateLeft = "<<<" 
    beego.TemplateRight = ">>>"
    

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-15 16:51:08

    beego doesn’t understand
    But if it’s a template conflict, just change Angular’s ​​template matching
    For example:

    app.config ($interpolateProvider) ->
      $interpolateProvider.startSymbol '//'
      $interpolateProvider.endSymbol '//'
    

    reply
    0
  • 高洛峰

    高洛峰2017-05-15 16:51:08

    If an error is reported on the server side, it must be an error when beego parses the template. Angular's template is pure HTML, because it is a front-end library, so if an error occurs, it will definitely be reported in the browser console. Where exactly something went wrong, you need to take out the code and analyze it for everyone.

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-15 16:51:08

    There is a Delims function in the template package, which may be what you need. It can change the identifier of the GO parsed template file

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-15 16:51:08

    The template syntax of golang is very close to the template syntax of angularJS, so it is easy to report errors. Here are two solutions.

    • Replace the angularJS template content in the homepage with the golang template tag, for example {{ user.name }} into {{ _user.name }}, and then use golang to render {{ _user.name }} into '{ { user.name }}'. This method can solve the problem, but it is cumbersome to teach.

    • Reduce the content on the homepage and try to include the corresponding routing template during design.

    reply
    0
  • Cancelreply