问题
i get a callback is not a function only when i try to add a new parameter erreur= TypeError: callback is not a function at services.js:72 i tried to add reference to the function when i romoved evrything works fine here's my code at service.js I hope you'll help me.
.factory('Payement', function ($http, $ionicLoading) {
return {
saveContratEtudant: function (_nb_piece1,_nb_piece2,_shortadresse,_govClt,_villeClt,_localiteClt,_voieClt,_cod_logem,_adresse_logem,_govLogem,_gelgLogem, _dateDel,_dateEffet,_dateExp,_nomAssure, _prenomAssure ,_piece2,_numDocument,_typeContrat,_natureContrat,_piece1,_dateNais,_email,_phone,_IdTrans,_reference,_numDocuemnt,_codePostal,_adresse,_typedocu,_sexeClt,_tarif,_frais ,_tva, _tcc, callback) {
$http({
method: 'POST',
url:SAVE_ETUDIANT,
timeout: 10000,
data: {
nb_piece1:_nb_piece1,
nb_piece2:_nb_piece2,
shortadresse:_shortadresse,
govClt:_govClt,
villeClt:_villeClt,
localiteClt:_localiteClt,
voieClt:_voieClt,
cod_logem:_cod_logem,
adresse_logem:_adresse_logem,
govLogem:_govLogem,
gelgLogem:_gelgLogem,
dateDelivra:_dateDel,
dateEffet:_dateEffet,
dateExp:_dateExp,
nomAssure:_nomAssure,
prenomAssure:_prenomAssure,
piece2:_piece2,
numDocument:_numDocument,
typeContrat:_typeContrat,
natureContrat:_natureContrat,
piece1:_piece1,
dateNais:_dateNais,
email:_email,
phone:_phone,
IdTrans: _IdTrans,
reference:_reference
numDocuemnt:_numDocuemnt,
codePostal:_codePostal,
adresse:_adresse,
typedocu:_typedocu,
sexeClt:_sexeClt,
//nbr_piece: ,
tarif : _tarif ,
frais : _frais,
tva :_tva,
tcc :_tcc,
//reference :_reference
},
}).then(function (response) {
callback(response);
// $ionicLoading.hide();
console.log("ajout ");
});
}
};
})
here's my code on my controller.js i tried to add a reference recently to my BD so in my controller i set a var ref and i get it the var show's in the console
sendbtn.addEventListener('click', function () {
Payement.saveContratEtudant($scope.nb_piece1,$scope.nb_piece2,$scope.shortadresse,$scope.govClt,$scope.villeClt,localiteClt,$scope.voieClt,$scope.cod_logem,$scope.adresse_logem,$scope.govLogem,$scope.gelgLogem,$scope.dateDelivra, $scope.dateEffet, $scope.dateExp, $scope.nomAssure,$scope.prenomAssure,$scope.piece2,$scope.numDocument,$scope.typeContrat,$scope.natureContrat,$scope.piece1, $scope.dateNais,$scope.email,$scope.phone, $scope.IdTrans,$scope.reference, $scope.numDocuemnt, $scope.codePostal, $scope.adresse,$scope.typedocu,$scope.sexeClt,$scope.tarif,$scope.frais,$scope.tva,$scope.tcc ,function (data) {
console.log("test saveContrat")
//console.log("date:",date)
if (data.data.state_code == 200){
$scope.local_ = data;
console.log($scope.local_.data.data);
$state.go('map')
} else {
$ionicPopup.alert({
title: "Alert",
template: data.data.message
});
}
});
this is the exact erro TypeError: callback is not a function
at services.js:72
at processQueue (ionic.bundle.js:29132)
at ionic.bundle.js:29148
at Scope.$eval (ionic.bundle.js:30400)
at Scope.$digest (ionic.bundle.js:30216)
at Scope.$apply (ionic.bundle.js:30508)
at done (ionic.bundle.js:24829)
at completeRequest (ionic.bundle.js:25027)
at XMLHttpRequest.requestLoaded (ionic.bundle.js:24968)
回答1:
It simply means that in this portion of code :
.then(function (response) {
callback(response); // <- HERE
// $ionicLoading.hide();
console.log("ajout ");
});
You are calling the function named "callback". But it's not defined. Probably because nothing is passed as param in the last param of this function :
saveContratEtudant: function (_nb_piece1,_nb_piece2,_shortadresse,_govClt,_villeClt,_localiteClt,_voieClt,_cod_logem,_adresse_logem,_govLogem,_gelgLogem, _dateDel,_dateEffet,_dateExp,_nomAssure, _prenomAssure ,_piece2,_numDocument,_typeContrat,_natureContrat,_piece1,_dateNais,_email,_phone,_IdTrans,_reference,_numDocuemnt,_codePostal,_adresse,_typedocu,_sexeClt,_tarif,_frais ,_tva, _tcc, callback) {
Splitted similar line :
saveContratEtudant: function (_nb_piece1,
_nb_piece2,
_shortadresse,
_govClt,
_villeClt,
_localiteClt,
_voieClt,
_cod_logem,
_adresse_logem,
_govLogem,
_gelgLogem, _dateDel,
_dateEffet,
_dateExp,
_nomAssure,
_prenomAssure ,
_piece2,
_numDocument,
_typeContrat,
_natureContrat,
_piece1,
_dateNais,
_email,
_phone,
_IdTrans,
_reference,
_numDocuemnt,
_codePostal,
_adresse,
_typedocu,
_sexeClt,
_tarif,
_frais,
_tva,
_tcc,
callback // <- HERE
) {
You should check if it's defined before calling it. Or check if your code provided really the function.
Pro tip : you should not have that much arguments in function.
So you should try like this :
.factory('Payement', function ($http, $ionicLoading) {
return {
saveContratEtudant: function (params, callback) {
$http({
method: 'POST',
url:SAVE_ETUDIANT,
timeout: 10000,
data: params,
}).then(function (response) {
callback(response);
// $ionicLoading.hide();
console.log("ajout ");
});
}
};
})
And call it like this :
Payement.saveContratEtudant($scope, function (data) {...})
来源:https://stackoverflow.com/questions/47940209/typeerror-callback-is-not-a-function