Reputation: 692
I am using ui.grid
and stuck with celledit
functionality. The row gets saved in DB, but shows an error as give below.
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
Controller:
$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;
Can anyone help me to resolve the issue? In particular, I don't understand why do we need a promise
in that function, even after reading the ui.grid
documentation.
Upvotes: 1
Views: 1936
Reputation: 5102
You need to set a valid promise associated with row save. From the documentation for setSavePromise:
Sets the promise associated with the row save, mandatory that the saveRow event handler calls this method somewhere before returning.
Controller:
$scope.saveRow = function( rowEntity ) {
var promise = ExpService.insertExp( rowEntity );
$scope.gridApi.rowEdit.setSavePromise( rowEntity, promise );
};
Upvotes: 1