【发布时间】:2016-02-21 14:11:09
【问题描述】:
问题在于属性 ng-click="deleteItem('{|{ reservation._links.self.href }|}')
<body ng-app="ReservationList">
<div class="content" ng-controller="ReservationListController">
<div class="panel" ng-repeat="reservation in reservations">
<div class="itemId{|{reservation.id}|}">
<button class="close" ng-click="deleteItem('{|{ reservation._links.self.href }|}')">X</button>
<div class="panel-heading clearfix">
<h3 class="panel-title">{|{ reservation.firstName }|}</h3>
<h3 class="panel-title">{|{ reservation.lastName }|}</h3>
</div>
</div>
</div>
</div>
</body>
有趣的是,当我检查 html 源代码时,ng-click 将如下所示:
ng-click="deleteItem('http://localhost:8080/reservation/1')"
但是,当启动 ng-click 函数时,它只会给出未编译的属性名称作为参数:
DELETE http://localhost:8080/%7B%7C%7B%20reservation._links.self.href%20%7D%7C%7D 405 (Method Not Allowed)
DELETE 请求应该以http://localhost:8080/reservation/1 作为端点,但不知何故,当我发送 DELETE 请求时它不会解析属性,只会因为这个未解析的 {[{ reservation._links.self.href }]} 而惹恼我。
我是否应该使用 HAL 链接作为 CRUD 操作的端点,还是将 id 提供给我的删除函数更明智。
请注意http://localhost:8080/reservation/1 上的 DELETE 请求在我硬编码时确实有效。
【问题讨论】:
-
Angular 中是否有类似“{|{ }]}”的东西,因为我从来没有遇到过这种情况
-
如果我没记错的话,你会期望 "{{ }}" 但是在角度你可以将语法更改为任何你想要的,所以我把它改成了 "{[{}]}" :)欲了解更多信息,你可以去docs.angularjs.org/api/ng/provider/$interpolateProvider
-
谢谢兄弟,我不知道这个。
标签: angularjs spring spring-mvc spring-boot spring-hateoas