(function () { 'use strict'; var name = 'adDelay'; angular.module('app.directive') .directive('adDelay', ['$window', function ($window) { return { require: 'ngModel', link: function (scope, element, attr, ctrl) { var group = attr[name + 'Group'] || ''; ctrl.$viewChangeListeners.push(function () { if (groupTimeout[group]) { $window.clearTimeout(groupTimeout[group]); } groupTimeout[group] = $window.setTimeout(function () { scope.$apply(function () { scope.$eval(attr[name]); }); }, attr[name + 'Timeout'] || 500); }); element.on('$destroy', function () { if (groupTimeout[group]) { $window.clearTimeout(groupTimeout[group]); groupTimeout[group] = null; } }); } }; }]); var groupTimeout = {}; })();