angularjs - How do I make angular.js reevaluate / recompile inner html? -
i'm making directive modifies it's inner html. code far:
.directive('autotranslate', function($interpolate) { return function(scope, element, attr) { var html = element.html(); debugger; html = html.replace(/\[\[(\w+)\]\]/g, function(_, text) { return '<span translate="' + text + '"></span>'; }); element.html(html); } })
it works, except inner html not evaluated angular. want trigger revaluation of element
's subtree. there way that?
thanks :)
you have $compile
inner html like
.directive('autotranslate', function($interpolate, $compile) { return function(scope, element, attr) { var html = element.html(); debugger; html = html.replace(/\[\[(\w+)\]\]/g, function(_, text) { return '<span translate="' + text + '"></span>'; }); element.html(html); $compile(element.contents())(scope); //<---- recompilation } })
Comments
Post a Comment