I have a directive that I put in the input of type class. I add the blur, focus event to know when I entered and exit the input to make the effect of the label (Material Design), but when I wrap the value through the angular ng-model I need to know that the field was filled.
Any idea?
app.directive('formControl', function() {
return {
restrict: 'C',
link: function (scope, element, attrs) {
// Add class filled to form-control's that have a value
if(element.val()){
element.parent().addClass('filled');
}
// Any event here that can tell me that the value was changed by the angular so I can put the css class
element.bind('blur', function (e) {
input = angular.element(e.currentTarget);
if(input.val()){
input.parent().addClass('filled');
} else {
input.parent().removeClass('filled');
}
input.parent().removeClass('active');
}).bind('focus', function (e) {
input = angular.element(e.currentTarget);
input.parent().addClass('active');
});
}
};
});