(function () { "use strict"; angular.module('app.directive') .directive('adCastNumber', [function () { return { require: 'ngModel', link: function (scope, element, attr, ctrl) { ctrl.$parsers.unshift(function (viewValue) { if (!(viewValue instanceof Number)) { viewValue = parseFloat(viewValue); } return viewValue; }); ctrl.$formatters.push(function (modelValue) { if (!(modelValue instanceof Number)) { modelValue = parseFloat(modelValue); } return modelValue; }); } }; }]) .directive('adCastFixed', ['$parse', function ($parse) { return { require: 'ngModel', link: function (scope, element, attr, ctrl) { var digits = angular.isDefined(attr['adCastFixed']) ? $parse(attr['adCastFixed'])(scope) : 2; ctrl.$parsers.unshift(function (viewValue) { if (!(viewValue instanceof Number)) { viewValue = parseFloat(viewValue); } return +viewValue.toFixed(digits); }); ctrl.$formatters.push(function (modelValue) { if (!(modelValue instanceof Number)) { modelValue = parseFloat(modelValue); } return +modelValue.toFixed(digits); }); } }; }]); ; })();