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

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -