app_directive.js 901 B

1234567891011121314151617181920212223242526272829303132
  1. define([
  2. 'angular',
  3. ],
  4. function (angular) {
  5. 'use strict';
  6. var module = angular.module('grafana.directives');
  7. module.directive('appConfigLoader', function($compile) {
  8. return {
  9. restrict: 'E',
  10. link: function(scope, elem) {
  11. var directive = 'grafana-app-default';
  12. //wait for the parent scope to be applied.
  13. scope.panelAdded = false;
  14. scope.$watch("current", function(newVal) {
  15. if (newVal && !scope.panelAdded) {
  16. if (newVal.module) {
  17. scope.panelAdded = true;
  18. directive = 'grafana-app-'+newVal.type;
  19. scope.require([newVal.module], function () {
  20. var panelEl = angular.element(document.createElement(directive));
  21. elem.append(panelEl);
  22. $compile(panelEl)(scope);
  23. });
  24. }
  25. }
  26. });
  27. }
  28. };
  29. });
  30. });