We can process selected text by user in browser window. We need to use window.getSelection or document.selection. In below example,  Mouse-Up event will be triggered when user selects the text, Then Angular function will process the selected text.

Markup

<div ng-mouseup="showSelectedText()">
Do you think that facebook, twitter...............
</div>
<div ng-bind="selectedText"></div>

Script

$scope.getSelectionText = function() {
      var text = "";
      if (window.getSelection) {
          text = window.getSelection().toString();
      } else if (document.selection && document.selection.type != "Control") {
          text = document.selection.createRange().text;
      }
      return text;
};

3 comments:

  1. Very nice, that's what I was looking for, thank you dude!

    ReplyDelete
  2. Very nice, that's what I was looking for, thank you dude!

    ReplyDelete
  3. Thanks a lot for the helpful post!

    ReplyDelete

Blogroll

Follow this blog by Email

Popular Posts