2

I have lines of text generated by ng-repeat, displayed within a div. I would like the user to be able to select from those lines and press a button, and have the application know which lines the user selected

Is there any way to do that in AngularJS

fracz
  • 20,536
  • 18
  • 103
  • 149
Victor Grazi
  • 15,563
  • 14
  • 61
  • 94
  • 2
    I really wish people would have the courtesy and good sense to add a comment explaining why the checked down a question – Victor Grazi Dec 28 '14 at 13:24

1 Answers1

1

In order to capture selected text in a browser, try the Rangy library. I have created a small example of how to use it. I'm sure you can expand it to match your needs.

If you need to take action immediately after user select the text (without button), you should listen for mouseup event. The following directive should help:

angular.module('myModule').directive('watchSelection', function() {
    return {
        link: function(scope, element) {
            element.on('mouseup', function(event) {
                var selection = rangy.getSelection();
                // do something with selected text
            });
        }
    };
});

You may also find this answer interesting.

Community
  • 1
  • 1
fracz
  • 20,536
  • 18
  • 103
  • 149