I am creating the custom directive for input
validation. Here I checked the input length, if input length is zero, it will show the error and am not unable to if an input is filled with characters, I want to hide it.
Here is my Code :
app.directive("formValidate", function() {
return {
require: 'ngModel',
template: '<p>Please Fill this Field</p>',
link: function(scope, elem, attr) {
scope.$watch(attr['ngModel'], function(value) {
if (((value || '').toString()).length == 0) {
var errorMessage = angular.element("<p class='error'>This field is requiured!</p>");
errorMessage.insertAfter(elem);
//$compile(errorMessage)(scope);
} else {
// What to do??
}
})
<input form-validate required md-no-asterisk ng-model="newEmployee.name" type="text" id="name" name="name">
with use of class as specified in the angular element
– Sathya Babu Ram k Nov 10 '17 at 06:42