Hello I have a problem with my validation directive. First of all I have directive that creates input element, in which I have directives that are based on some parameters that tell if this calidation should be fired up or not... It looks like this:
app.directive('ngAttr', function($compile){
return {
scope:{},
link: function (scope, element, attrs){
var opts = scope.$eval(attrs.ngAttr);
if(opts.condition){
element.attr(opts.attrName, opts.condition)
}
}
};
});
It adds attribute based on condition passed to it... If I want to add a directive conditionally I do:
ng-attr="{condition: {{opts.validatePhone}}, attrName:'validate-phone'}"
as an attribute tu my previous directive that creates an input... And the problem is that the validate-phone directive is fired up only once when the directive is created it doen't react on input handlers... The code of validate directive is:
app.directive('validatePhone', function($compile){
return{
require: 'ngModel',
link: function(scope, element, attrs, ngModel){
function validate(val){
console.log(val)
}
scope.$watch(function() {
return ngModel.$viewValue;
}, validate);
}
};
});
Not it is simple but console.log() dosn't work when I change input.
I created a plunker so it will be easier to check it if someone has an idea... http://plnkr.co/edit/CgVCV58goFS9GKLBtRrw?p=preview