PanelLoader.ts 809 B

1234567891011121314151617181920212223242526272829303132
  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. load(elem, panel, dashboard): AttachedPanel {
  10. var template =
  11. '<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);