2
var todoApp = angular.module('TodoApp', ['ngResource']);
todoApp.value('restTodo', 'api/1/todo/:id');
var todoCtrl = todoApp.controller('TodoCtrl', function($scope, $resource, restTodo) {
$scope.src = $resource(restTodo);
//add & refresh
$scope.src.save({ content: 'hello world', done: false });
$scope.todos = $scope.src.get();
//OR
//delete & refresh
$scope.src.delete({ id: '1' });
$scope.todos = $scope.src.get();
});
当我添加/删除项目并再次从服务器读取待办事项列表以刷新它。我发现,我会打这个错误不时:AngularJS如何处理异步呼叫
System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.
有人说我可以把MultipleActiveResultSets=true;
成连接字符串,但我怀疑它只会隐藏我的问题,因为GET显然是想有一个肮脏的在DELETE完成其工作之前阅读。
在基于事件的风格语言中,我会在DELETEComplete()事件后自然地调用GET。但是,我是AngularJS的新手,我不确定这是如何完成的?请帮忙。
我明白了,所以有如何使用成功回调。谢谢。我试试看。 – Tom