Is there a standard way to create new Angular directives by extending existing directives?
Specifically I'd like to customize angular-contenteditable
to allow more control over editing options, like preventing newlines:
<h1 my-custom-content-editable prevent-newlines="true">Hello, world!</h1>
Where the implementation is something like:
app.directive("myCustomContentEditable", function() {
return {
link: function($scope, elem, attrs) {
angular.element(elem).on("keydown", function($event) {
if (attrs.preventNewlines && $event.keyCode == 13)
$event.preventDefault();
});
},
};
})
What would be the best way to extend the contenteditable
directive in my custom directive?
Note that I do know that I can combine the directives at the markup level — <h1 contenteditable my-custom-content-editable>…</h1>
— but I'd like to know specifically how to create a single directive that extends another.