Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
181
rated 0 times [  184] [ 3]  / answers: 1 / hits: 5778  / 11 Years ago, tue, january 28, 2014, 12:00:00

i've found this thread, which is from great help, but there is a problem that i couldn't solve. When you initialize the value in the controller the value doesn't 'get' with the mask



here a example.
Thanks


More From » angularjs

 Answers
4

I opened a thread in the portuguese stackoverflow and they gave me the help. The important thing was that same function that was used to format the value when happened some change has to be used when the value is 'put in the field'.



app.directive('format', ['$filter',
function($filter) {
return {
require: '?ngModel',
link: function(scope, elem, attrs, ctrl) {
if (!ctrl) return;


ctrl.$formatters.unshift(function(a) {
elem[0].value = ctrl.$modelValue
elem.priceFormat({
prefix: '',
centsSeparator: ',',
thousandsSeparator: '.'
});
return elem[0].value;
});

ctrl.$parsers.unshift(function(viewValue) {
elem.priceFormat({
prefix: '',
centsSeparator: ',',
thousandsSeparator: '.'
});
return elem[0].value;
});
}
};
}
]);



[#48293] Monday, January 27, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rohan

Total Points: 403
Total Questions: 93
Total Answers: 105

Location: Trinidad and Tobago
Member since Mon, Jul 13, 2020
4 Years ago
;