Skip to content

Instantly share code, notes, and snippets.

@IlanFrumer
Created February 3, 2014 08:46
Show Gist options
  • Save IlanFrumer/8780645 to your computer and use it in GitHub Desktop.
Save IlanFrumer/8780645 to your computer and use it in GitHub Desktop.
ngModel + contenteditable support for angular.js
app.directive "contenteditable", ->
require: "?ngModel"
link: (scope, element, attrs, ngModel) ->
if(ngModel)
# view -> model
element.bind "blur", ->
scope.$apply ->
ngModel.$setViewValue(element.html())
# model -> view
ngModel.$render = ->
element.html(ngModel.$viewValue || '')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment