gumga-counter
Version:
Gumga Counter
21 lines (20 loc) • 800 B
JavaScript
(function () {
'use strict';
Counter.$inject = ['$compile'];
function Counter($compile) {
return {
restrict: 'A',
require: ['^form', 'ngModel'],
link: function (scope, elem, attrs) {
scope._max = parseInt(attrs.gumgaMaxLengthText);
if (!isNaN(parseInt(attrs.gumgaCounter))) {
scope._max = parseInt(attrs.gumgaCounter);
}
var template = '<p class="{{_max <= teste.length ? \'text-danger\' : \'text-muted\'}}">{{_max <= ' + attrs.ngModel + '.length ? "Você passou o limite de ' + scope._max + ' caracteres" : _max - ' + attrs.ngModel + '.length + " caracteres restantes" }}</p>';
elem.after($compile(template)(scope));
}
};
}
angular.module('gumga.counter', [])
.directive('gumgaCounter', Counter);
})();