How do I make angular.js reevaluate / recompile inner html?

后端 未结 3 1640
慢半拍i
慢半拍i 2020-12-08 00:26

I\'m making a directive that modifies it\'s inner html. Code so far:

.directive(\'autotranslate\', function($interpolate) {
    return function(scope, elemen         


        
3条回答
  •  [愿得一人]
    2020-12-08 01:09

    You have to $compile your 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 '';
          });
          element.html(html);
          $compile(element.contents())(scope); //<---- recompilation 
        }
      })
    

提交回复
热议问题