ng-click on checkbox not updating $pristine property of form

后端 未结 1 722
难免孤独
难免孤独 2021-01-20 16:08

$pristine property of the form is not updated when the hidden text is updated for first time AngularJS

I have got a form in AngularJS and I want to know if any fiel

相关标签:
1条回答
  • 2021-01-20 16:32

    Use the ng-change directive instead of ng-click:

      <input type="checkbox" name="awesome" ng-model="formData.awesome" 
             ng-true-value="ofCourse" ng-false-value="iWish" 
             ̶n̶g̶-̶c̶l̶i̶c̶k̶=̶"̶o̶n̶C̶l̶i̶c̶k̶(̶)̶"̶
             ng-change="onClick()" > Are you awesome?
    

    The ng-change directive adds a $viewChangeListener that is invoked after the user operates the control.

    The ng-click directive adds a click handler that is invoked before the ngModelController updates the model.

    Note: Checkboxes can be focused using the tab key and operated with the enter key as well as by clicking with the mouse.

    For more information, see

    • AngularJS ng-change Directive API Reference
    0 讨论(0)
提交回复
热议问题