Skip to content

Instantly share code, notes, and snippets.

@alanklement
Created September 11, 2013 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanklement/6524324 to your computer and use it in GitHub Desktop.
Save alanklement/6524324 to your computer and use it in GitHub Desktop.
angular.module('appApp').directive('vzContenteditable', function () {
return {
require: 'ngModel',
link: function (scope, elm, attrs, ctrl) {
// view -> model
elm.bind('blur', function () {
scope.$apply(function () {
var string = elm.html().replace(/(\r\n|\n|\r)/gm, " ").replace(/\s+/g, " ").replace(/ /g, '');
ctrl.$setViewValue(string);
});
scope.$apply(attrs.save);
});
// model -> view
ctrl.$render = function (value) {
elm.html(value);
};
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment