Reputation: 11157
I have this code which is a contenteditable placeholder by CraigStuntz.
My question is where should I put this code so all the div
which contain contenteditable
will get effected.
I tried to put under app.controller('myCtrl', function(){});
but it only works with the direct scope. No nested scope is working.
angular.element(document.querySelectorAll('div[contenteditable]')).bind('change keydown keypress input', function() {
if (this.textContent) {
this.setAttribute('data-contenteditable-placeholder', 'true');
}
else {
this.removeAttribute('data-contenteditable-placeholder');
}
});
Upvotes: 1
Views: 123
Reputation: 8407
Try using a directive like this.
angular.module('angularProject.directives', [])
.directive('placeholder', function() {
return {
restrict:'A',
link: function(elem) {
elem.bind('change keydown keypress input', function() {
elem.setAttribute('data-contenteditable-placeholder', 'true');
});
}
}
});
You can then place it in any of your divs like this.
<div placeholder></div>
I haven't tested this.
Upvotes: 4