angularjs - 为什么我的 go 服务说我的“项目”不是从我的服务器定义的?
问题描述
我运行我的 go 服务,然后出现这个错误,我不知道如何解决它(恐慌:模板:index.html:20:函数“项目”未定义)它假设是针对我的 html 但我如何可以解决它:
代码 HTML(角度)
<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>
去服务
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)
}
解决方案
Go 模板解析器找到了 Angular 表达式并想要解释它们。它没有找到名为 的函数item
。
您需要应用其中一种解决方案
- 在模板中使用字符串
{{`{{Your.Angular.Data}}`}}
{{"{{"}}
使用,转义表达式{{"}}"}}
- 使用不同的分隔符
tpl = template.Must(template.ParseGlob("Views/*").Delims("<(",")>"))
在您的情况下,您不使用任何模板功能,因此您可以删除它们。
推荐阅读
- r - 在R中使用for循环求和
- django - 如何将外键添加到 Django 字段历史记录?
- c# - 可以测试方法参数上所需的注释吗?
- c - 在函数内使用 malloc() 后“写访问冲突”
- python-3.x - 如何更有效地编写此代码以使其运行得更快?
- sql - 如何使用 pandas 明智地更新/插入(upsert)大表块
- java - 我正在尝试制作一个在键入“空格”键时发射子弹的游戏
- dart - 飞镖如何将列表分配给新的列表变量
- c# - C# 使用“UploadFromStream”方法将文件从 MongoDB 迁移到 Azure Blob 存储不起作用
- java - 清单合并失败,出现多个错误,org.gradle.api.tasks.TaskExecutionException:任务执行失败