(function(angular, $) {

  'use strict';

  var module = angular.module('jqAutoComplete', []);

  module.directive('jqAutocomplete', function() {
    return {
      restrict: 'EA',
      link: function(scope, tElement, tAttrs) {
        var $input = angular.element(tElement).find('input');

        var opts = angular.extend(tAttrs, {
          transformResults: function(data) {
            var results = scope.transformResults({
              $results: data
            });
            return angular.isDefined(results) ? results : data;
          },
          onShown: function() {
            scope.$apply(function() {
              scope.onShown();
            });
          },
          onHidden: function() {
            scope.$apply(function() {
              scope.onHidden();
            });
          },
          select: function(obj) {
            scope.$apply(function() {
              scope.ngModel = obj;
              scope.ngChange();
            });
          },
          unSelect: function() {
            scope.$apply(function() {
              scope.ngModel = undefined;
              scope.ngChange();
            });
          }
        });

        $input.jqAutoComplete(opts);
      },
      scope: {
        ngModel: '=',
        ngChange: '&',
        onShown: '&',
        onHidden: '&',
        transformResults: '&'
      },
      template: function() {
        return '' +
          '<span>' +
          '  <input type="text" />' +
          '</span>';
      },
      replace: true
    };
  });

})(angular, jQuery);

@@ -1129,32 +1129,170 @@
             %7D);%0A
+          %7D,%0A          onDestroyed: function() %7B%0A            scope.$apply(function() %7B%0A              scope.onDestroyed();%0A            %7D);%0A
           %7D%0A    
@@ -1307,16 +1307,36 @@
 %0A       
+ var $autocomplete =
  $input.
@@ -1356,16 +1356,139 @@
 e(opts);
+%0A%0A        scope.$on('$destroy', function() %7B%0A          $autocomplete.destroy();%0A          $autocomplete = null;%0A        %7D);
 %0A      %7D
@@ -1586,32 +1586,58 @@
  onHidden: '&',%0A
+        onDestroyed: '&',%0A
         transfor

add angular destroy callback