Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
Cómo devolver un cierre o manija que no devuelve un cierre

Soy nuevo en angular y estoy trabajando en un proyecto en mi empresa donde tengo que implementar una función de eliminación.

Me las arreglé para implementar la función donde el usuario sigue adelante con la eliminación. Pero si cambia de opinión en el último minuto y cancela la confirmación de eliminación, recibo un error.

Aquí está mi código:

 $scope.deleteButtonClick = function () { if ($scope.hasRemove()) { $scope.deleting = true; //Fetch the promise and add our own state management to it var promise = $scope.removeAction(); // this remove action calls the below 'remove' function if (!promise.then) { throw "Wizard's bound 'deleteAction' must return a closure." } promise.then(function () { $scope.deleting = false; }, function () { $scope.deleting = false; }); } };

La siguiente es la función de eliminación donde quiero devolver un cierre.

 $scope.remove = function () { if (confirm("Confirm Delete?")){ var data = {}; data.id = EventService.event.id; // delete return $http.post('/admin/deleteAjax/', data).then( function (response) { if (response.data.status == 'success') { RegistryService.getItem("successModal").show(); setTimeout(()=>{ location.replace("/admin/index") }, 2000); } else if (response.data.status == 'error'){ RegistryService.getItem("errorModal").show(); } } ); } else { // This is where I need to return a closure // when user presses 'cancel' button how can I return a closure or skip the error? } };

El siguiente es el error que recibo cuando return false en la sección else .

La 'deleteAction' enlazada del asistente debe devolver un cierre. indefinido

¿Alguien tiene una idea de cómo solucionar este problema?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El problema es que $scope.remove() necesita devolver una Promesa, y la cláusula else en el bloque confirm() no devuelve una Promesa.

Para hacer eso, puede usar el servicio AngularJS $q para crear una Promesa y devolverla.

Así que tu bloque else se vería así:

 } else { // This is where I need to return a closure // when user presses 'cancel' button how can I return a closure or skip the error? const deferred = $q.defer(); // <------------ use $q service to create a deferred deferred.resolve({ cancelled: true }); // <-- resolve it to whatever value you want return deferred.promise; // <---------------- and return its promise }

Aquí hay un violín que muestra este enfoque.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!