我试图保持资源列表保持最新为用户与之互动。使用AngularJS ngResource我最初使用它的查询
方法抢单。然后,每个资源有一个 $删除
(或 $删除
)的方法,对吗?但是,烧制后的资源不会被删除从列表从查询
返回。
I'm trying to keep a list of resources up to date as a user interacts with it. Using an AngularJS ngResource I initially grab the list using it's query
method. Each resource then has a $remove
(or $delete
) method, right? But when fired, the resource isn't removed from the list returned from query
.
这是问了很多,我知道,但我几乎希望它只是为我做的一切。保存,我怎么能做到这一点。请问资源本身散发出某种事件?它有一个删除属性,我可以 $观看
?我将如何去知道,资源是 $删除
倒是这样我就可以拼接出来的名单?
This is asking a lot, I know, but I was almost hoping it would just do everything for me. Save that, how could I accomplish this. Does the resource itself emit some kind of event? Does it have a deleted property I can $watch
? How would I go about know that a resource was $remove
'd so I can splice it out of the list?
感谢。
推荐答案
您必须使用阵列
的拼接
方法来删除它( $指数
是NG-repeat的隐式索引)。
You have to use Array
's splice
method to remove it ($index
is ng-repeat's implicit index).
$scope.removeItem = function (index) {
$scope.items[index].$delete();
$scope.items.splice(index, 1);
}
然后在你的HTML
And then in your HTML
<a ng-click="removeItem($index)">remove me</a>
相关推荐
最新文章