I created a directive where it serves as a mask for checking account, so when I type a value, always the rightmost value in the input is the digit of my account, until then beauty is working. The problem is that I do not want to change the value of my ng-model if I inform for example 123456 should appear in my view 12345-6 and my ng-model should only be 123456 (without the trace). What is happening and that my ng-model is being changed (12345-6). Does anyone know how to solve this ??
My view is correct, the policy caters to me
NOTE: In the bottom left corner look at my ng-model
angular.module('app').directive('contaCorrenteMask', function () {
return {
restrict: 'A',
require: "ngModel",
link: function (scope, element, attrs, ctrl) {
var _formatContaBanco = function (data) {
if (!data)
return data;
if (data.length == 1)
return data;
data = data.replace(/[^0-9]+/g, "");
var digito = data.slice(-1);
var conta = data.slice(0, -1);
return conta + '-' + digito;
};
// Send out changes from inside:
scope.$watch(attrs.ngModel, function (val) {
scope.model = val;
ctrl.$setViewValue(_formatContaBanco(scope.model));
ctrl.$render();
});
}
};
})