angularjs-directiverangy

Text Highlighter directive don't work on button click from outside the directive


I have implemented a highlighter directive with assistance of rangy library.

Please have a look at current implementation of highlighter directive: http://plnkr.co/edit/mYrEfehaTIbzvS0hePq2?p=preview plunker.

Here , I have button within the template which onclick toggles the selection.

Now, I want the same behaviour but this time, button needs to be outside directive template.

Can you help me with it ?


Solution

  • After adding $watch to look out for , I am able to handle the issue.

    scope.$watch(function(){return scope.highlight;}, function(value) { cssApplier.toggleSelection(); });

    Running code is at : http://plnkr.co/edit/mYrEfehaTIbzvS0hePq2?p=preview

    Hope it helps someone.