1

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) 
}
Community
  • 1
  • 1
Mua Knight
  • 41
  • 7

1 Answers1

4

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?

Grzegorz Żur
  • 47,257
  • 14
  • 109
  • 105