I want nothing to happen if you press enter when in editable for content:
this is what i tried inside the directive:
element.on('blur keyup change', function (e) {
if(e.which == '13')
e.preventDefault();
Here is the whole directive:
.directive('contenteditable', function () {
return {
restrict: 'A',
require: '?ngModel',
link: function (scope, element, attrs, ngModel) {
if (!ngModel) return;
ngModel.$render = function () {
element.html(ngModel.$viewValue || '');
};
element.on('blur keyup change', function (e) {
if(e.which == '13')
e.preventDefault();
scope.$apply(readViewText);
});
function readViewText() {
var html = element.html();
console.log(html);
html = html.replace(/(<([^>]+)>)/ig,"");
console.log(html)
ngModel.$setViewValue(html);
}
}
};
});
source
share