0

i am new on angular js, working on form validations. I have done all but still validation doesn't work. Here is my code:

<form role="form" name="studentForm" class="form-horizontal" novalidate>
    <div class="form-group">
        <label for="student_email" class="col-sm-2 control-label">Email</label>
        <div class="col-sm-10">
            <input type="email" name="student_email" ng-model="studentEmail" class="form-control" id="student_email" required>
            <div role="alert" class="error-msg" ng-messages="studentForm.student_email.$error">
                <p ng-message="required">Your email is required.</p>
            </div>
        </div>
    </div>
</form>

Script:

angular.module('app', ['ngMessages']);
5
  • Is it possible for you to create a Plunkr for this? This will help others to look into the issue and provide solutions. Commented Apr 19, 2016 at 6:56
  • Have you included <script src="angular-messages.js"> on your page? Commented Apr 19, 2016 at 6:57
  • No errors in the console ? Commented Apr 19, 2016 at 6:57
  • @garethb yes script is included. Commented Apr 19, 2016 at 7:03
  • @load , yes a very strange error. i have included the angular.min.js Commented Apr 19, 2016 at 7:04

2 Answers 2

2

Here is the working Demo for your code.

 <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
 <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-messages.js"></script>
 <script src="script.js"></script>

May be you forgot to add the scripts in your html files. The position of the scripts in the index.html file also matters. the ng-message should only include below the angular.min.js

Please check the demo

Sign up to request clarification or add additional context in comments.

2 Comments

is it possible to hide message onload? i mean i want to show whenever we touch that field.
Have a look at $touched
0

https://docs.angularjs.org/guide/forms

Note that novalidate is used to disable browser's native form validation.

try removing the novalidate from the form tag:

<form role="form" name="studentForm" class="form-horizontal">

I hope it helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.