Wednesday, June 11, 2014

Validation in Angular JS

For validation in Angular Js, first of all use 'required' attribute in the input control like..

Now restrict the save button so that it is clickable only when all the validation succeeds. Use  
ng-disabled="myform.$invalid" where myform is the name of the form. Placing the input controls and save button under form tag is must

Doing this is sufficient to validate the form. If you want to give the user a required message then use a span like this..



So * will be shown when you leave a required field empty


One thing to remember is that for this required message will be shown only when the input control (textbox) should have a name attribute and name in 'ng-show' attribute of the span should also be there.


No comments:

Post a Comment