Angular - append html through different frames with one module per frame

前端 未结 1 1582
囚心锁ツ
囚心锁ツ 2021-01-03 09:11

My code have the main windonw and one iframe and each one with your module. A button in main window fires click event that should append html into iframe, the new html when

相关标签:
1条回答
  • 2021-01-03 09:48

    I've tried this code and it seems work fine! I found it here: http://www.snip2code.com/Snippet/50430/Angular-Bootstrap

    var $rootElement = angular.element(document.getElementById("frame").contentWindow.document);
    var modules = [
      'ng',
      'module2',
      function($provide) {
        $provide.value('$rootElement', $rootElement)
      }
    ];
    
    var $injector = angular.injector(modules);
    
    var $compile = $injector.get('$compile');
    
    $rootElement.find("div#divId").append(scope.content);
    
    var compositeLinkFn = $compile($rootElement);
    
    var $rootScope = $injector.get('$rootScope');
    compositeLinkFn($rootScope);
    
    $rootScope.$apply();
    
    0 讨论(0)
提交回复
热议问题