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

135
Views
How to add $watch for form validation inside AngularJS class

I try to add a $watch to check if the form is valid or not.

// testCtrl.html

 ....
             <div class="row" ng-form="testCtrl.testForm">
                            ...
                      <div class="form-group">
                        <label>NAME</label>
                        <input
                            class="form-control"
                            id="name"
                            type="text"
                            ng-model="testCtrl.testEdit.displayName"
                            autofocus
                            required />
                      </div>
    ...

// testCtrl.js

 ...
    class TestController {
        constructor($scope,
                    ...
                    ) {
    ...
        }
    ...
    
    canSaveTest() {
        return this.testForm.$valid;
    }

...

I want to add a watcher in this way:

$scope.$watch('testForm.$invalid', function(isInvalid)          {
        $scope.disableNextBtn = isInvalid;
});

But I'm not sure in which part of the code I need to add this watcher.

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

0

I just added validateData for ng-change:

// testCtrl.html ...

                   <input
                        class="form-control"
                        id="name"
                        type="text"
                        ng-model="testtCtrl.testEdit.displayName"
                        ng-change="testCtrl.validateData()"
                        autofocus
                        required
                    />

// testCtrl.js

validateData() {
            this.disableNextBtn = !this.testForm.$valid;
    }
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!