angularjs - Angular $watch event isn't firing on change in window.getSelection().anchorNode -
i watch changes in user highlighted text. trigger base on dom element being highlighted. have following function:
$scope.$watch(function(scope) { return window.getselection().anchornode }, function() { console.log(window.getselection().anchornode; }
it fires once when page loads , never again, regardless of text highlight. highlight text in various spans, text areas on page, , doesn't fire.
if add $interval function nothing, watch fire when selection changes after interval time.
any ideas ?
in instance $watch won't work because no $scope variable being updated , $digest cycle won't start.
you can try use ngmouseup directive last highlighted text , save it.
html:
<div ng-mouseup="updatehighlightedtext()">lots of text</div> js:
$scope.updatehighlightedtext = function () { $scope.highlightedtext = window.getselection().tostring(); } here working example in jsfiddle
Comments
Post a Comment