Skip to content

Instantly share code, notes, and snippets.

@ianmcnally
Created June 30, 2014 17:30
Show Gist options
  • Save ianmcnally/89dd4945d24b5cd2002d to your computer and use it in GitHub Desktop.
Save ianmcnally/89dd4945d24b5cd2002d to your computer and use it in GitHub Desktop.
Update input on blur - Angular
# Only update <input> elements with bound angular models <input ng-model="my model"> on 'blur' event.
# Tweaked from a variety of places.
app.directive 'updateOnBlur', ->
require : 'ngModel'
link : (scope, element, attributes, ngModelController) ->
element.unbind 'input'
element.bind 'blur', ->
scope.$apply ->
ngModelController.$setViewValue element.val()
@ianmcnally
Copy link
Author

Note: this was before ng-model-options!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment