app.directive("money", function() {
return {
restrict : "A",
require: 'ngModel',
link:function($scope,elm,attr,ngModel){
ngModel.$viewChangeListeners = [function() {
var val = ''+ngModel.$modelValue;
var result = ngModel.$modelValue;
if ((val/1).toString() === 'NaN') {
result = '';
}
if (val.split('.')[1]&&val.split('.')[1].length>2) {
result = _.floor(ngModel.$modelValue,2);
}
ngModel.$setViewValue(""+result);
ngModel.$render();
}].concat(ngModel.$viewChangeListeners);
}
};
});
网友评论