javascript - Angular digest cycle is not run for the first time -
here jsfiddle.
in text box first time keypress symbol effecting ng-model because element(blur)
. how can remove symbol first keypress itself.
app.directive('format', ['$filter', function ($filter) { return { require: 'ngmodel', scope: { val : '=val' }, link: function (scope, elem, attrs, ctrl) { if (!ctrl) return; ctrl.$formatters.unshift(function (a) { if(attrs.symbol == '$') return $filter(attrs.format)(ctrl.$modelvalue, '$') else return $filter(attrs.format)(ctrl.$modelvalue) }); elem.bind('blur', function(event) { var = elem.val(); var plainnumber = a.split('.').filter(function(e){ return (e.length > 0); }).join('.'); var = 0; if(isnan(parsefloat(plainnumber))){ = (attrs.symbol == '$') ? 1 : 3; } var num = plainnumber.substring(i, plainnumber.length).replace(/,/g,''); if(attrs.symbol == '$') elem.val($filter('currency')(num, attrs.symbol)); else elem.val($filter('currency')(num)); var n =parsefloat(num); scope.val = number(n); if(!scope.$$phase) { scope.$apply(); } }); } }; // controller }])
when keypress symbol effecting ng-model. when give click on outside symbol not effecting ng-model. want remove symbol first keypress self
i new angularjs. please me.
update:
when entering text box ng-model containing symbol. when click outside of textbox removing symbol , not effecting ng-model. want is, when entering value ng-model should not contain symbol.
Comments
Post a Comment