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

154
Views
Checkbox is binded using ng-model and has an ng-change directive that executed a POST request on change. How to uncheck back if the request fails?

I have an array of objects that looks like this:

pausedAssessments = [
    {
        id: 0,
        name: 'Name 1',
        paused: false
    },
    {
        id: 1,
        name: 'Name 2',
        paused: false
    },
]

I then render some HTML for each assessment:

<div ng-repeat="pausedAssessment in pausedAssessments">
    <span class="switch">
        <input ng-model="pausedAssessment.paused" name="{{pausedAssessment.name}}" ng-change="onPauseResumeAssessmentHandler(pausedAssessment)" type="checkbox" toggle-btn on-type="success">
    </span>
</div>

And my ng-change function looks like this:

  $scope.onPauseResumeAssessmentHandler = function onPauseResumeAssessmentHandler(systemAssignedAssessment) {
    const { id, paused } = systemAssignedAssessment;
    const clientId = $scope.client.clientId;

    AssessmentsService.pauseResumeAssessment(clientId ,id, !paused);
  };

Now since my input checkbox is binded to pausedAssessment.paused, if I check it the paused property becomes true and the checkbox gets checked, however, I only want it to become checked if AssessmentsService.pauseResumeAssessment(clientId ,id, !paused); does not fail as it's a POST request.

For example, if the checkbox was unchecked and I clicked it, I'd want it to check only if the POST request goes through and for it to either stay unchecked, or to uncheck itself if the POST request fails.

My problem is that since it's binded, it changes the paused property to true and checks itself as soon as its clicked.

about 4 years ago · Juan Pablo Isaza
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!