GolangNote

Golang笔记

解决angularjs 变量标签和go 的template 标签相同问题

Permalink

angularjs 的变量标签和 go 的 template 的默认标签相同

angularjs 的hello world

HTML: angularjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!doctype html>
<html ng-app>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
  </head>
  <body>
    <div>
      <label>Name:</label>
      <input type="text" ng-model="yourName" placeholder="Enter a name here">
      <hr>
      <h1>Hello {{yourName}}!</h1>
    </div>
  </body>
</html>

可以自定义 GoLang template 分隔符

Go: template
1
2
indexTmpl = template.New("index.html").Delims("<<", ">>")
indexTmpl, _ = indexTmpl.ParseFiles("index.html")

如果你的项目已经开始,就用 {{"{{"}}{{"}}"}},如:

HTML: angularjs
1
2
3
{{"{{"}} 1 + 2 {{"}}"}}
{{ printf "{{}}"}}
{{ printf "{{yourName}}"}}

本文网址: https://golangnote.com/topic/95.html 转摘请注明来源

Related articles

Write a Comment to "解决angularjs 变量标签和go 的template 标签相同问题"

Submit Comment Login
Based on Golang + fastHTTP + sdb | go1.22.3 Processed in 0ms