$resource执行promise的自动扩展(作为一种方便的方法),并将响应附加到返回的对象本身,但在直接操作数据时,尤其是在解析之前尝试访问数据时,就不会这么做了。因此,如果您想操纵数据,则需要等待承诺得到解决。
i、 电子:-
//chain through the promise.
Message.query().$promise.then(function(messages){
$scope.messages = messages.filter(function(obj) {
return (obj.id != 6);
});
});
或者您也可以(使用现有代码):
$scope.messages.$promise.then(function(messages){
//Since you are overwriting the object here, there will no longer be a $Promise property so be careful about it when you try to chain through elsewhere after this
$scope.messages = messages.filter(function(obj) {
return (obj.id != 6);
});
});