UNPKG

landers.angular

Version:

landers.angular

30 lines 1.22 kB
;angular.module('Landers.angular') .directive('uiAlertError', ['Flat', function(Flat){ return { restrict : 'A', link : function($scope, $ele, $attrs){ var datKey = $attrs['uiAlertError']; $ele.addClass('alert alert-danger').hide(); $scope.$watch(datKey, function(newValue){ if (newValue) { var html = '<i class="fa fa-minus-circle"></i> ' + newValue; $ele.html(html).show(); } else { $ele.hide(); } }); var $form = $ele.closest('form'); $form.find('input, select, textarea').change(function(){ var ele = $(this); if (!ele.val()) return; var ngmodel = ele.attr('ng-model'); var arr = ngmodel.split('.'); arr.splice(1, 0, '$errors'); var datkey = arr.join('.'); $timeout(function(){ Flat.set($scope, datkey, ''); }); }); } }; }])