douyue8364 2018-11-06 09:25
浏览 45
已采纳

为什么我的go服务说我的“项目”不是从服务器定义的?

I running my service of go and then there is this error that i don´t know how to solve it (panic: template: index.html:20: function "item" not defined) it suppose to be for my html but how i can solve it:

Code HTML (Angular)

<table id="mytable" class="table table-bordred table-striped">
  <tr>
   <th>ID</th>
   <th>Name</th>
   <th>Last Name</th>
   <th>Second Last Name</th>
  </tr>
  <tbody>
   <tr ng-repeat="item in ListOfUsers">
    <td ng-if="ListOfUsers.length!==0">{{item._id}}</td>
    <td ng-if="ListOfUsers.length!==0">{{item._name}}</td>
    <td ng-if="ListOfUsers.length!==0">{{item._lastName}}</td>
    <td><a class="btn btn-primary btn-xs" href="#!EditUser/{{item.Id}}">
    <span class="glyphicon glyphicon-pencil"></span></a>
    </td>
    <td><a class="btn btn-danger btn-xs"ref="#!DeleteUser/{{item.Id}}">
    <span class="glyphicon glyphicon-trash"></span></a>
    </td>
   </tr>
  </tbody>
 </table>

Go Service

func main(){
    fs := http.FileServer(http.Dir("Resources"))
    go print10000numbers("world")
    print10000numbers("hello")
    router := mux.NewRouter()
    router.HandleFunc("/People",GetPeopleHandler).Methods("GET")
    router.HandleFunc("/InsertPeople",InsertPersonHandler).Methods("POST")
    router.HandleFunc("/UpdatePeople/{id}",UpdatePersonHandler).Methods("POST")
    router.HandleFunc("/DeletePeople/{id}",DeletePersonHandler).Methods("DELETE")
    router.Handle("/Resources/Angular/angular.js",http.StripPrefix("/Resources", fs))
    router.Handle("/Resources/JS/AppController.js",http.StripPrefix("/Resources", fs))
    tpl = template.Must(template.ParseGlob("Views/*"))
    fmt.Println("Listening")
    router.HandleFunc("/",chargeHtml).Methods("GET")
    http.ListenAndServe(":8081",router)
}
func chargeHtml(w http.ResponseWriter,r *http.Request){
    tpl.ExecuteTemplate(w,"index.html",nil) 
}
  • 写回答

1条回答 默认 最新

  • douzhang3898 2018-11-06 09:28
    关注

    Go template parser found Angular expressions and wanted to interpret them. It found no function named item.

    You need to apply one of the solutions

    1. use strings in templates {{`{{Your.Angular.Data}}`}}
    2. escape the expressions using {{"{{"}}, {{"}}"}}
    3. use different delimiters

    tpl = template.Must(template.ParseGlob("Views/*").Delims("<(",")>"))

    In the your case you don't use any template features so you can drop them.

    Source How do I escape “{{” and “}}” delimiters in Go templates?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥20 Python安装cvxpy库出问题
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题