Created
July 3, 2015 06:58
-
-
Save jbmyid/2ddd736f806470e62694 to your computer and use it in GitHub Desktop.
Open ng-typeahea on click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.directive('typeaheadClickOpen', function($parse, $timeout) { | |
var dir; | |
return dir = { | |
restrict: 'A', | |
require: 'ngModel', | |
link: function($scope, elem, attrs) { | |
var triggerFunc; | |
triggerFunc = function(evt) { | |
var ctrl, prev; | |
ctrl = elem.controller('ngModel'); | |
prev = ctrl.$modelValue || ''; | |
ctrl.$setViewValue(prev ? '' : ' '); | |
if (prev) { | |
return $timeout(function() { | |
return ctrl.$setViewValue("" + prev); | |
}); | |
} | |
}; | |
return elem.bind('click', triggerFunc); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment