我正在學習angularjs,我能夠列出通過REST API接收到的數據。我將數據顯示在一個表中,並在其中一列中我想要有一個刪除按鈕,最終將進行DELETE調用以從數據庫中刪除該特定記錄。下面是我使用HTML:如何將數據傳遞給角度控制器?
<table st-table="displayedCollection" st-safe-src="hosts" class="table table-striped">
<thead>
...
</thead>
<tbody>
<tr ng-repeat="x in displayedCollection">
<td>{{x.hostname}}</td>
<td>{{x.ipaddress}}</td>
<td>{{x.macaddress}}</td>
<td>
<button
type="button"
class="btn btn-default btn-sm"
ng-click="delete_record({{x._id}})">
<span class="glyphicon glyphicon-remove"></span>
</button>
</td>
</tr>
</tbody>
...
</table>
這給了我這個錯誤:
Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 16 of the expression [delete_record({{x._id}})] starting at [{x._id}})].
我的控制器看起來是這樣的:
app.controller("meanVoyCtrl", function($scope,$http) {
...
$scope.delete_record = function(id) {alert("id is ["+id+"]");};
...
});
現在,如果我能我會很高興只需要彈出一個alert
顯示要刪除的記錄的_id
。
我在這裏做錯了什麼?
感謝
_「你只需要如果你是一個角指令外使用大括號」 _ - 不管你受到外界的意思,語句是不正確的。花括號是否可以使用取決於指令的期望。他們中的一羣**做**期望模板,'ngHref'例如OP代碼不起作用的原因是表達式在插入之前被解析。否則,即使使用大括號也可以工作。 – zeroflagL
是的,你是對的。由於他沒有使用期望模板的角度指令,因此我不想深入討論這個簡單的問題。 –