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();
});

When I add/delete item(s) and read the todo list from server again to refresh it. I find that I will hit this error from time to time:

System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.

Someone said I can put MultipleActiveResultSets=true; into connect string, but I suspect it will only hide my issue, because the GET is obviously trying to have a dirty read before DELETE can finish its job.

In event based style language, I will naturally call GET after a DELETEComplete() event. However, I am new to AngularJS, I am not sure how it is done here? Please help.

1 Answer 1

2

I am not a expert, but I would place the read code in the success callback of the save. Something like this:

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 }, 
      function(data) {
       $scope.todos = $scope.src.get();
    });
});
Sign up to request clarification or add additional context in comments.

1 Comment

i see, so there is how to use the success callback. thank you. i give it a try.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.