2016-10-10 99 views
0

这是用HTML视图和模型的角度控制器类基本角度web应用

我的角度控制脚本文件包含

var taskResource = $resource("http://localhost:3000/api/tasks/:id", { id: '@id' }); 

$scope.tasks = taskResource.query(); 

    noError = function() { 
     $scope.error = ""; 

    } 

    onFailure = function() { 
     $scope.error = "Error communicating with server"; 
    } 

$scope.changeTaskDone = function (task) { 
     $scope.tasks.$save(task, noError, onFailure); 

     }; 

我的HTML包含

<tr ng-class="{'task-done': task.done}" ng-repeat="task in tasks | orderBy: '-priority'"> 
         <td class="small-cell"> 
          <button type="button" class="btn btn-xs btn-danger" ng-click="deleteTask(task)"> 
           <span class="glyphicon glyphicon-remove"></span> 
          </button> 
         </td> 
         <td class="small-cell"> 
          <input type="checkbox" ng-model="task.done" ng-change="changeTaskDone(task)" /> 
         </td> 

noError和OnFailure回调没有被调用。

编辑 localhost是我开发的一个节点服务器。我应该从节点服务器发送什么信息才能使成功回调在客户端激活。 现在它只发送一个res.status(200);

+0

找不到或未被调用的方法?你有任何错误信息? –

+0

这些方法没有被调用。我使用视觉工作室。如果将调试点放在onError和onFailure上,并且在我停止本地主机服务器时未命中 –

+0

,则会调用OnFailure。所以错误回调正在工作。但成功回调NoError不是。 –

回答

1

你需要调用由$资源实例的引用,例如:

$scope.changeTaskDone = function (task) { 
    taskResource.save(task, noError, onFailure); 
}; 
+0

taskResource.save(task,noError,onFailure); 当localhost关闭时,onerror回调OnFailure正在工作。但是当localhost运行时,成功回调不是。 –

+1

你能举例说明吗? –

+0

错误不在客户端,而在服务器端。我也是在节点编程并在客户端表达 –

0

在节点服务器,我没有使用沿着res.status(200)res.send();