I am new to form validation using Angular JS so I looked around a lot and found one that was a nice tutorial. The tutorial can be found here. I know there are a few posts on Stack Overflow about ng-messages
however I reviewed them and they do not seem to pertain to my issue.
I have installed ng-messages
using bower and am running it with grunt
. There are no error however my validation messages do not seem to fire off.
My HTML is as follows:
<form name="myForm" novalidate>
<fieldset>
<div id="number" ng-class="{ 'has-error' : myForm.clientNumber.$invalid && !myForm.clientNumber.$pristine }">
<label for="client">SRF #: *</label>
<input type="text" name="clientNumber" placeholder="Enter SR #" ng-minlength="3" ng-maxlength="9" required>
<div ng-messages="myForm.clientNumber.$error">
<!--<div ng-message="required" >SRF # is required.</div>-->
<div ng-message="minlength" >SRF Number is too short.</div>
<!--<div ng-message="maxlength">SRF Number is too long.</div>-->
</div>
</div>
</fieldset>
</form>
Part of my app.JS is as follows:
angular
.module('myApp', [
// Angular
'ngAnimate',
'ngCookies',
'ngResource',
'ngSanitize',
'ngTouch',
'ui.router',
'myApp.home',
'restangular',
'ngMessages'
])
Part of my controller is as follows:
(function() {
'use strict';
angular.module('myApp.home', [
'ui.router',
'myApp.myFactory',
'ngMessages'
])
.config(homeConfig)
.controller('homeCtrl', home);
homeConfig.$inject = ['$stateProvider'];
home.$inject = ['$http','myFactory','$timeout'];
function home($http,myFactory,$timeout) {
...
}
What I have looked at and tried:
- ngMessages/angular validation not working
- ng-messages is not working
- https://github.com/angular/material/issues/6440
- https://github.com/angular/material/issues/2820
- https://docs.angularjs.org/api/ngMessages
- http://www.yearofmoo.com/2014/05/how-to-use-ngmessages-in-angularjs.html
Some in the list are tutorials while others are posts on Stack Overflow: ngMessages/angular validation not working.
I do not understand why it does not work. All sites I have seen look to be implementing the same way.