javascript - Angular $parser won't work in attribute directive with input template -
i need leave attribute, company rules.
here jsfiddle:
http://jsfiddle.net/m3szn/
i can't seem console.logs work $parser when type input box.
var module = angular.module("demo", []); module.directive('lowercase', function() { homecoming { require: 'ngmodel', restrict: 'a', scope: { ngmodel: '=' }, link: function(scope, element, attr, ngmodelcntrl) { ngmodelcntrl.$formatters.unshift(function (text) { console.log('from formatters: '); }); ngmodelcntrl.$parsers.push(function (text) { console.log('from parsers: '); }); }, template: '<input ng-model="ngmodel" type="text">', }; }); function demo($scope) { $scope.data = 'some value'; }
and here html:
<div ng-app="demo" ng-init="" ng-controller="demo"> <div lowercase ng-model="data"></div> </div>
i have tried lot includes following:
usingrequire: '^ngmodel',
instead. removing scope, though need rest of directive i'm using. changing names utilize mymodel pass in model. and lot of other things have lost track of. edit i able working this: http://jsfiddle.net/m3szn/2/
html:<div ng-app="demo" ng-init="" ng-controller="demo"> <input lowercase ng-model="data" type="text"> </div>
js var module = angular.module("demo", []); module.directive('lowercase', function() { homecoming { require: 'ngmodel', restrict: 'a', link: function(scope, element, attr, ngmodelctr) { ngmodelctr.$formatters.unshift(function (text) { console.log('from formatters: '); }); ngmodelctr.$parsers.push(function (text) { console.log('from parsers: ' + text); homecoming text; }); } }; }); module.controller('demo', demo); function demo($scope) { $scope.data = 'some value'; }
by removing template , putting model straight onto input field.
this not ideal, since utilize template since have ton of attributes need go on input field. avoid duplication each time utilize directive.
javascript angularjs angularjs-directive
No comments:
Post a Comment