I'm trying to watch the content of ng-html-bind and modify the div content to auto link all hyperlinks in the div since the original content will not have hyperlink html.
Here is the plunker
Here is the directive
app.directive('autolink', ['$compile', '$timeout', function ($compile, $timeout) { return { restrict: 'EA', replace: true, link: function (scope, element, attrs) { $timeout(function () { var text = element[0].innerHTML; var linkTypes = ["http://", "https://"]; linkTypes.forEach(function (linkType) { var startSpace = 0; while (startSpace >= 0) { text = element[0].innerHTML; var locationOfHttp = text.indexOf(linkType, startSpace); if (locationOfHttp < 0) break; var locationOfSpace = text.indexOf(" ", locationOfHttp); var textAfter = ""; if (locationOfSpace < 0) { locationOfSpace = text.length; } else { textAfter = text.substring(locationOfSpace, text.length); } var linkUrl = text.substring(locationOfHttp, locationOfSpace); var htmlText = text.substring(0, locationOfHttp) + '<a href="' + linkUrl + '">' + linkUrl + '</a>' + textAfter; element[0].innerHTML = htmlText; startSpace = (text.substring(0, locationOfHttp) + '<a href="' + linkUrl + '">' + linkUrl + '</a>').length - 1; } }); scope.$apply(); console.log("autolink"); }, 1); }, }; }]); My directive is working when the page loads but not when I click on the change URL, div is not auto linking. How do I watch for the change and run the directive on change ?