How to implement an ng-change for a custom directive

If you require ngModel you can just call $setViewValue on the ngModelController, which implicitly evaluates ng-change. The fourth parameter to the linking function should be the ngModelCtrl. The following code will make ng-change work for your directive. link : function(scope, element, attrs, ngModelCtrl){ scope.updateModel = function(item) { ngModelCtrl.$setViewValue(item); } } In order for your solution … Read more

Angularjs dynamic ng-pattern validation

This is an interesting problem, complex Angular validation. The following fiddle implements what you want: http://jsfiddle.net/2G8gA/1/ Details I created a new directive, rpattern, that is a mix of Angular’s ng-required and the ng-pattern code from input[type=text]. What it does is watch the required attribute of the field and take that into account when validating with … Read more