PanelLoader.ts 868 B

12345678910111213141516171819202122232425262728293031323334
  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. console.log('AttachedPanel:Destroy, id' + panel.id);
  21. panelScope.$destroy();
  22. compiledElem.remove();
  23. }
  24. };
  25. }
  26. }
  27. coreModule.service('panelLoader', PanelLoader);