只有在我尝试添加新功能时才会收到回调功能 参数erreur = TypeError:回调不是函数 在services.js:72我尝试添加对函数的引用,当我认为evrything工作正常时,我的代码在service.js我希望你能帮助我。
.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 ");
});
}
};
})
这里是我的控制器上的代码。我最近在我的控制器上添加了一个引用,所以在我的控制器中我设置了一个var ref,我得到了var show' s控制台
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
});
}
});
这是确切的错误 TypeError:回调不是函数
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)
答案 0 :(得分:0)
它只是意味着在这部分代码中:
.then(function (response) {
callback(response); // <- HERE
// $ionicLoading.hide();
console.log("ajout ");
});
您正在调用名为&#34; callback&#34;的函数。但它没有定义。可能是因为在这个函数的最后一个参数中没有任何东西作为参数传递:
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) {
拆分类似的行:
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
) {
在调用之前,您应该检查它是否已定义。或者检查您的代码是否真的提供了功能。
专业提示:你的功能不应该那么多。
所以你应该这样试试:
.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 ");
});
}
};
})
并称之为:
Payement.saveContratEtudant($scope, function (data) {...})