我有一个ngRepeat
元素,其中包含一个触发确认消息的删除按钮。我正在尝试使用动态表达式来显示确认消息:
<div ng-repeat="item in items">
<a ng-click="delete(item_id)"></a>
<span ng-class="{'show':'delete_'+item._id}">Are you sure you want to delete your review? </span>
</div>
不幸的是,我无法将'delete_'+item._id
表达式显示在ngClass
指令中。有人可以提供解决方案吗?
答案 0 :(得分:2)
只要表达式ng-class="{'show': 'delete_' + item._id}"
评估为show
(总是如此),使用'delete_' + item._id'
就会添加类true
。当用户点击show
标记,即true
时,您可能希望a
旁边有一个ng-class="{'show': userWantsToDelete(item)}"
的表达式。
此外,如果要将类'delete_' + item._id
添加到元素,则可以在元素上使用带有class
属性的角度表达式,即class="{{'delete_' + item._id}}"
。
答案 1 :(得分:0)
尝试这个。
<a ng-click="delete = !delete">delete</a>
<span ng-class="{show: delete}">Are you sure you want to delete your review? </span>
如果您要显示上次点击的<a>
在视图中
<a ng-click="delete(item._id)">delete</a>
<span ng-class="{show: item._id==delete_id}">Are you sure you want to delete your review? </span>
在控制器中
$scope.delete = function(id) {
$scope.delete_id = ($scope.delete_id == id) ? !id : id;
}