I am learning JavaScript and AngularJS.
I want to disable text selection with Angular Directive.
I have a JavaScript code for that function:
function clearSelection() {
if(document.selection && document.selection.empty) {
document.selection.empty();
}
else if(window.getSelection) {
var sel = window.getSelection();
sel.removeAllRanges();
}
};
And I am working on the directive, but don't know how to add that function to the directive.
Directive:
...
.directive('disableTextSelection', function() {
return {
link: function($scope, $element, $attrs) {
// Something here..
}
}
}
...
And I want to do this in HTML like:
<table disable-text-selection>
...
</table>