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 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号