PanelLoader.ts 804 B

12345678910111213141516171819202122232425262728293031
  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 = '<plugin-component type="panel" class="panel-height-helper"></plugin-component>';
  11. var panelScope = this.$rootScope.$new();
  12. panelScope.panel = panel;
  13. panelScope.dashboard = dashboard;
  14. const compiledElem = this.$compile(template)(panelScope);
  15. const rootNode = angular.element(elem);
  16. rootNode.append(compiledElem);
  17. return {
  18. destroy: () => {
  19. panelScope.$destroy();
  20. compiledElem.remove();
  21. },
  22. };
  23. }
  24. }
  25. coreModule.service('panelLoader', PanelLoader);