我正在使用ui.grid
并坚持使用celledit
功能。该行保存在DB中,但在下面显示错误。
angular.min.js:2 A promise was not returned when saveRow event was raised, either nobody is listening to event, or event handler did not return a promise
控制器:
$scope.saveRow = function( rowEntity ) {
// create a fake promise - normally you'd use the promise returned by $http or $resource
//var promise = $q.defer();
ExpService.insertExp(rowEntity);
/*console.log(rowEntity);
$scope.gridApi.rowEdit.setSavePromise( rowEntity, promise.promise );
promise.resolve();*/
};
$scope.gridOptions.onRegisterApi = function(gridApi) {
// set gridApi on scope
$scope.gridApi = gridApi;
gridApi.rowEdit.on.saveRow($scope, $scope.saveRow);
};
ExpService:
var exp={};
exp.insertExp = function(insData){
return $http.post(config.expInsertURL, insData).then(function(repos){
return repos.data;
},function(error){
alert("Error happened while getting response \n" + error);
return "";
});
}
return exp;
有人可以帮我解决这个问题吗?特别是,我不明白为什么即使在阅读promise
文档之后我们也需要ui.grid
函数。
答案 0 :(得分:1)
您需要设置与行保存关联的有效承诺。来自documentation for setSavePromise:
设置与行保存相关联的承诺,强制表示 saveRow事件处理程序在返回之前在某处调用此方法。
控制器:
$scope.saveRow = function( rowEntity ) {
var promise = ExpService.insertExp( rowEntity );
$scope.gridApi.rowEdit.setSavePromise( rowEntity, promise );
};