简体   繁体   中英

Angular validation on form not working

I have a form and I want to check if all the fields are valid or not.

Currently I am using four different methods. Nothing is working. Here is my plunker:

http://plnkr.co/edit/c4czI1W1fvXR4881SP1z?p=preview

Here are the methods I am using to check for validity

<button ng-click="my.$valid && validityCheck()">Update</button>
<div>myForm.$valid = {{myForm.$valid}}</div>
<span ng-show="myForm.$valid" style="color:green">Yippii!</span>
<span ng-show="myForm.$invalid" style="color:red">Not :(</span>

Plunkder code has few errors.

  • Missing angular script tag
  • ng-click should refer to myForm instead of my. ng-click="myForm.$valid
  • Inject $scope to controller (or use this ). function($scope){

http://plnkr.co/edit/Twz9E9LnQ08IpweLARjG

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM