PanelLoader.ts 807 B

123456789101112131415161718192021222324252627282930313233
  1. import angular from 'angular';
  2. import coreModule from 'app/core/core_module';
  3. export interface AttachedPanel {
  4. destroy();
  5. }
  6. export class PanelLoader {
  7. /** @ngInject */
  8. constructor(private $compile, private $rootScope) {
  9. }
  10. load(elem, panel, dashboard): AttachedPanel {
  11. var template = '<plugin-component type="panel" class="panel-height-helper"></plugin-component>';
  12. var panelScope = this.$rootScope.$new();
  13. panelScope.panel = panel;
  14. panelScope.dashboard = dashboard;
  15. const compiledElem = this.$compile(template)(panelScope);
  16. const rootNode = angular.element(elem);
  17. rootNode.append(compiledElem);
  18. return {
  19. destroy: () => {
  20. panelScope.$destroy();
  21. compiledElem.remove();
  22. }
  23. };
  24. }
  25. }
  26. coreModule.service('panelLoader', PanelLoader);