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();
});
当我添加/删除项目并再次从服务器读取待办事项列表以刷新它时。我发现我会不时遇到这个错误:
System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.
有人说我可以放入MultipleActiveResultSets=true;
连接字符串,但我怀疑它只会隐藏我的问题,因为 GET 显然试图在 DELETE 完成其工作之前进行脏读。
在基于事件的样式语言中,我自然会在 DELETEComplete() 事件之后调用 GET。但是,我是 AngularJS 的新手,我不确定它是如何在这里完成的?请帮忙。