angularjs - How to add a class css into directive? -


i have directive use change text of input uppercase, works fine, want show text capitalize when user type, note want keep text uppercase show user should capitalize. created css class don't know how use css directive.

how add css class directive ?

trying.

css

.textcapitalize {   text-transform: capitalize; } 

directive

var app = angular.module('starter');  app.directive('uiuppercase', function(){      return {         require:'ngmodel',         link: function(scope, element, attr, ctrl){                      element.addclass('textcapitalize'); //show text capitalized             var _textformat = function(input){                 return input.length > 0 ? input.touppercase() : "";             }              element.bind('keyup', function(){                 ctrl.$setviewvalue(_textformat(ctrl.$viewvalue));                                ctrl.$render();             });          }      };  }); 

try this:

app.directive('uiuppercase', function() {    return {        restrict: 'a',       require: 'ngmodel',        link: function(scope, element, attr, ctrl) {          function adduppercaseclass(ngmodelvalue) {              if(!element.hasclass("textcapitalize"))                 element.addclass("textcapitalize");         }         ctrl.$parsers.push(adduppercaseclass);        }    }; }); 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -