javascript - Using Angular formatters / parsers -


can't seem angular formatters , parsers working:

app.js:

var itemapp = angular.module('itemapp', []);  itemapp.controller('itemcontroller', ['$scope',  function($scope) {        $scope.some_value = 'abcefg';  }]);  itemapp.directive('changecase', function () {     return {           restrict: 'a',           require: 'ngmodel',           link: function (scope, element, attrs, ngmodel) {              ngmodel.$formatters.push(function(value){               return value.touppercase();             });              ngmodel.$parsers.push(function(value){               return value.tolowercase();             });            }     }; }); 

view.html:

  <input ng-model="some_value" changecase> 

it doesn't work- no errors, nothing happens values in input or model. i'm newish angular, having trouble figuring out how i'd debug this.

try write:

<input ng-model="some_value" change-case> //camel-case 

this explained in angular docs

normalization

angular normalizes element's tag , attribute name determine elements match directives. typically refer directives case-sensitive camelcase normalized name (e.g. ngmodel). however, since html case-insensitive, refer directives in dom lower-case forms, typically using dash-delimited attributes on dom elements (e.g. ng-model).

the normalization process follows:

  • strip x- , data- front of element/attributes.
  • convert or _-delimited name camelcase.

Comments

Popular posts from this blog

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

wordpress - (T_ENDFOREACH) php error -

Using django-mptt to get only the categories that have items -