2017-07-12 4 views
1

Ich würde gerne wissen, ob es möglich war, mehrere Seiten in einem einzigen Controller zu aktualisieren? Ich muss meine Startseite aktualisieren, nachdem ich Daten zu meiner Liste hinzugefügt habe. Momentan benutze ich einen Pull um meine Homepage zu aktualisieren, aber ich möchte sie nach einem Eintrag in meiner Liste aktualisieren.Aktualisieren mehrerer Seiten in einem Controller

mein Controller:

.controller('addCRCtrl', function ($scope, $state, $stateParams, $ionicPopup, $ionicLoading, $timeout, AppService) { 

let loadData =() => { 
    $ionicLoading.show(); 
    $scope.loading=true; 
    $scope.form = {}; 
    $scope.formProjet = {}; 
    $scope.form.patient = idjeune; 
    $scope.form.dateVisite = new Date(); 
    AppService.patient(idjeune).then(function (response) { 
    $scope.patient = response; 
    console.log(response); 
    }); 
    AppService.user().then(function (response) { 
    $scope.bene1 = response; 
    console.log(response); 
    }); 
    AppService.hopitaux().then(function (response) { 
    $scope.hopitaux = response; 
    }); 

    AppService.lieuxlist().then(function (response) { 
    $scope.lieux = response; 
    }); 
    AppService.userByAntenneAddCR().then(function (response) { 
    console.log(response); 
    $scope.listeBene = JSON.parse(JSON.stringify(response)); 
    }); 
    AppService.typeVisite().then(function (response) { 
    $scope.listeVisite = JSON.parse(JSON.stringify(response)); 
    }); 
    AppService.projet(idjeune).then(function (response) { 
    $scope.projets = response; 
    }); 
    AppService.getCategorie().then(function (response) { 
    $scope.categorieprojet = response; 
    console.log(response); 
    if (update) { 
     $scope.updating = update; 
     $scope.form.dateVisite = new Date(cr.date); 

     for (let i in $scope.lieux) { 
     if ($scope.lieux[i].id == cr.idLieu) { 
      $scope.lieu = $scope.lieux[i]; 
      break; 
     } 
     } 
     $scope.form.lieudetail = cr.lieudetail; 
     $scope.bene1 = { 
     id: cr.bene1, 
     nom: cr.benevole1 
     } 
     $scope.bene2 = { 
     id: cr.bene2, 
     nom: cr.benevole2 
     } 
     $scope.bene3 = { 
     id: cr.bene3, 
     nom: cr.benevole3 
     } 
     console.log("Benevole 1 : ", $scope.bene1); 
     console.log("Benevole 2 : ", $scope.bene2); 
     console.log("Benevole 3 : ", $scope.bene3); 
     $scope.form.description = cr.compteRenduVisite; 
     $scope.form.todo = cr.todo; 
     $scope.form.etatpatient = cr.etatPatient; 
     for (let i in $scope.listeVisite) { 
     if ($scope.listeVisite[i].id == cr.typeVisite) { 
      $scope.typeVisite = $scope.listeVisite[i]; 
      break; 
     } 
     } 
     for (let i in $scope.projets) { 
     if ($scope.projets[i].id == cr.idProjet) { 
      $scope.projet = $scope.projets[i]; 
      break; 
     } 
     } 
     $timeout(() => { $ionicLoading.hide(); $scope.loading=false;;}, 6000); 
    } 
    else 
     $timeout(() => { $ionicLoading.hide(); $scope.loading=false;}, 2000); 
    }); 
} 
$scope.$on('$ionicView.beforeEnter', function (event, viewData) { 
    loadData(); 
}); 
$scope.addCr = function() { 
    $ionicLoading.show(); 
    let isValid = $scope.form.dateVisite && $scope.patient && $scope.bene1 && $scope.form.description && $scope.form.todo; 
    isValid = isValid && $scope.form.etatpatient && $scope.typeVisite; 
    let formInvalid =() => { 
    $ionicLoading.hide(); 
    var alertPopup = $ionicPopup.alert({ 
     template: '<p style="text-align: center;">Veuillez renseigner tous les champs</p>' 
    }); 
    } 
    if (!isValid) { 
    formInvalid(); 
    return; 
    } 
    $scope.form.lieu = ($scope.lieu)? $scope.lieu.id:0; 
    $scope.form.bene1 = $scope.bene1.id; 
    $scope.form.bene2 = ($scope.bene2) ? $scope.bene2.id : null; 
    $scope.form.bene3 = ($scope.bene3) ? $scope.bene3.id : null; 
    $scope.form.lieudetail = ($scope.form.lieudetail) ? $scope.form.lieudetail : "-"; 

    let temp = $scope.form.dateVisite; 
    //$scope.form.dateVisite = $scope.form.dateVisite.toISOString().slice(0, 10); 
    let newProject = false; 
    $scope.form.typeVisite = $scope.typeVisite.id; 
    switch ($scope.typeVisite.id) { 
    case 3: 
     newProject = true; 
     isValid = isValid && $scope.cprojet && $scope.formProjet.description && $scope.formProjet.titre; 
     break; 
    case 4: 
    case 5: 
     if ($scope.projet) $scope.form.projet = $scope.projet.id; 
     isValid = isValid && $scope.projet; 
     break; 

    default: 
     $scope.form.projet = 0; 
     break; 
    } 

    for (var i in $scope.hopitaux) { 
    if ($scope.hopitaux[i].nom === $scope.patient.hopital) { 
     $scope.form.hopital = $scope.hopitaux[i].id; 
    } 
    } 
    for (var j in $scope.form) { 
    if ($scope.form[j] == null) { 
     if (j == 'bene2' || j == 'bene3') 
     $scope.form[j] = 0; 
     else 
     delete $scope.form[j]; 
    } 
    } 
    if (!isValid) { 
    formInvalid(); 
    return; 
    } 
    let callService =() => { 
    var myform = angular.copy($scope.form); 
    if (update) 
     myform.dateVisite = new Date($scope.form.dateVisite.getTime() + 86400000).toISOString().slice(0, 10); 
    else 
     myform.dateVisite = $scope.form.dateVisite.toISOString().slice(0, 10); 
    console.log(myform); 
    let idtogo = (update) ? cr.id : null; 
    AppService.addCR(myform, idtogo).then(function (response) { 
     update = false; 
     cr = null; 
     var alertPopup = $ionicPopup.alert({ 
     title: 'Ajout Réussie !', 
     template: '<p style="text-align: center;">Merci d\'avoir renseigné les informations relatives à la visite !</p>' 
     }); 
     $scope.form.dateVisite = temp; 
     console.log(response); 
     $ionicLoading.hide(); 
     $state.reload('menu.ficheJeune'); 
     $state.go('menu.ficheJeune'); 
    }); 
    } 
    if (!newProject || update) 
    callService(); 
    else { 
    $scope.formProjet.categorie = $scope.cprojet.id; 
    $scope.formProjet.patient = idjeune; 
    var myprojectform = angular.copy($scope.formProjet); 
    console.log(myprojectform); 
    AppService.addProject(myprojectform).then((response) => { 
     console.log(response); 
     if (response) { 
     AppService.projet(idjeune).then(function (response) { 
      for (let i in response) { 
      console.log("Response :", response); 
      let temp = false; 
      for (let j in $scope.projets) { 
       if (response[i].id == $scope.projets[j].id) { 
       temp = true; 
       } 
      } 
      if (!temp) { 
       $scope.form.projet = response[i].id; 
       callService(); 
       break; 
      } 
      } 
     }); 
     } 
    }); 
    } 
}; 
AppService.refreshToken().then(function (response) { 
    if ($scope.token) { 
    console.info('Refresh'); 
    } 
}); 
}) 

Vorerst meine erste Seite zu aktualisieren ich tun:

$state.reload('menu.ficheJeune'); 
$state.go('menu.ficheJeune'); 

Aber ich würde auch eine zweite Seite 'menu.home' genannt aktualisieren möchten.

danke ich Ihnen im Voraus

Antwort

1

Sie dies in Ihrem homeCtrl verwenden können:

$scope.$on('$ionicView.beforeEnter', function() { 
    console.log('beforeEnter'); 
    // your code 
}); 
+0

danke :) es Arbeit ist – AlexisCraig

Verwandte Themen