JSFiddle - React, Tailwind, and code Playground
HTML
<div ng-app="App" ng-controller="MainController">
Amount
<input ng-model="vars.value" ng-change="updateValue(vars.value)" ng-delay="1000" />
</div>
JavaScript
var app =
angular
.module('App', []);
app.controller('MainController', function ($scope) {
$scope.vars ={}
$scope.vars.value= '0.00 $';
$scope.updateValue = function (value) {
$scope.vars.value = parseFloat(value).toFixed(2) + " $"
};
});
app.directive('ngDelay', ['$timeout', function ($timeout) {
return {
restrict: 'A',
scope:true,
compile: function (element, attributes) {
var expression = attributes['ngChange'];
if (!expression)
return;
attributes['ngChange'] = '$$delay.execute()';
return {
pre: function (scope, element, attributes) {
scope.$$delay = {
expression: expression,
delay: scope.$eval(attributes['ngDelay']),
execute: function () {
var state = scope.$$delay;
state.then = Date.now();
$timeout(function () {
if (Date.now() - state.then >= state.delay)
scope.$eval(expression);
}, state.delay);
}
};
}
}
}
};
}]);