【发布时间】:2016-06-18 23:40:39
【问题描述】:
假设我有以下...
myService = Restangular.all('things');
myService.getList().then(
// success
function(things) {
$scope.things = things;
},
// failure
function(things) {
// do whatever, stuff failed
}
)
现在我有了$scope.things,它是来自 api 的 things 的集合,一切都很好。
我想发布一个新的thing,并返回承诺,以便我可以在其他地方处理通过/失败
return $scope.things.post(newThing) // A promise...
但是,以这种方式执行操作不会自动将我的新 thing 添加到 $scope.things 集合中。为什么不?我已经看到链接到restangular 文档的enhanced promises 部分并提到“推送”方法的问题,但这对我没有帮助,因为$scope.things 没有“推送”方法。
这里发生了什么?我在哪里弄糊涂了。
【问题讨论】:
-
有一个替代解决方案,无需使用 push() 方法刷新整个列表。我已经在一个类似的问题中回答了这个问题。请查看下方stackoverflow.com/a/37898582/3664759
标签: angularjs restangular