Ich benutze angular js mvc ie. UI, Controller und Service. Ich habe einen Code geschrieben, der prüft, ob die gleiche Organisation in der Datenbank vorhanden ist oder nicht. Zu diesem Zweck habe ich einen AJAX-Aufruf geschrieben. die mich zurückgeben, wenn der Name in der Datenbank vorhanden ist oder nicht in Form von '0' oder '1'. dh "1" für Gegenwart und "0" für Abwesenheit. Ich überprüfe diese Antwort im Controller und wenn die Antwort eine ist, gebe ich "false" an die aufrufende Funktion zurück, aber obwohl alles gut geht, sehe ich den Variablenwert immer noch als 'undefiniert'. Im Folgenden finden Sie den Code ein:Programmablauf verhält sich abnormal in angularjs
Controller:
$scope.checkOrgName = function(){
console.log("We are checking id organization name "+$scope.organization.orgName+" is already present in the database or not");
if($scope.organization.orgName != ""){
OrganizationService.checkOrgName($scope.organization.orgName).then(
function(data){
var dbOrgName = data;
if(dbOrgName==1){
(Command comes here and shows the following alert box on the UI)
$scope.failureAlertMessage("This organization name is already present, enter some other name");
$scope.organization.orgName = "";
return false;(here I am returning false)
}
else if(dbOrgName==0){
console.log("Organization name is available");
return true;
}
},
function(errResponse){
$scope.failureAlertMessage("Error while checking organization name in the database");
}
);
}else{
console.log("No need for the organization name checking, name empty");
}
}
Aufruf der Funktion (in der Steuerung nur)
(Here I am calling the above function)
$scope.orgNameStatus = $scope.checkOrgName();
console.log("$scope.orgNameStatus: "+$scope.orgNameStatus);(This line prints 'undefined')
if($scope.orgNameStatus == false){
return false;
}
Browser Console:
Inside addOrganization
organization_controller.js:51 We are checking id organization name dsd is already present in the database or not
organization_service.js:25 In service: check org name
organization_controller.js:171 $scope.orgNameStatus: undefined
organization_controller.js:217 Validation status: true
organization_controller.js:59 Command in dbOrgName==1
Was ist falsch an Code? Bitte hilf mir, Danke. !!
teilen sich ein zupfen, wenn möglich, oder die Angabe, wo dieser Fehler durch Überprüfung Konsole geschieht. –
Ich werde Inhalte der Konsole einfügen – Vish