I have a made a directive as a kind of wrapper around input tags. But the problem is the error is not getting changed and the callback function is getting called only the first time.
(function() { 'use strict'; angular .module('demoApp') .directive('mmInputTag', function () { return { restrict: 'E', require: 'ngModel', scope : { label: "@", name: "@", type: "@", domId: "@", className: "@" }, template: ['<label for={{id}}>{{label}}</label>', '<input type={{type}} name={{name}} id={{domId}} class={{className}}>' ], link: function(scope, elem, attrs, ngModel) { scope.$watch(function() { return ngModel.$error }, updateErrors); function updateErrors(data){ console.log("error", data, ngModel.$error) } elem.on("change", function() { console.log(ngModel.$error) scope.$apply() }); } } }); }()) <mm-input-tag label="Name" type="text" name="name" domId="profile_name" className="form-control" ng-model="vm.profile.name" ng-required="true" ng-maxlength="255"/> the directive is inside a form, I have two question, for the first time, it shows only Object{require: true} for ngModel.$error , but there is nothing for the ng-maxlength . why? and why doesn't the ngModel.$error changing ?, what I am trying to achieve is I declare one directive like that, and it would add a <label><input /> <p ng-show="form.name.$dirty">Errro message</p> -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscr...@googlegroups.com. To post to this group, send email to angular@googlegroups.com. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.