Commit dd5814b5 by Ryan McKinley Committed by GitHub

Runtime: expose angular injector (#24262)

parent 1eb52465
......@@ -4,3 +4,4 @@ export * from './dataSourceSrv';
export * from './LocationSrv';
export * from './EchoSrv';
export * from './templateSrv';
export * from './legacyAngularInjector';
import { auto } from 'angular';
let singleton: auto.IInjectorService;
/**
* Used during startup by Grafana to temporarily expose the angular injector to
* pure javascript plugins using {@link getLegacyAngularInjector}.
*
* @internal
*/
export const setLegacyAngularInjector = (instance: auto.IInjectorService) => {
singleton = instance;
};
/**
* WARNING: this function provides a temporary way for plugins to access anything in the
* angular injector. While the migration from angular to react continues, there are a few
* options that do not yet have good alternatives. Note that use of this function will
* be removed in the future.
*
* @beta
*/
export const getLegacyAngularInjector = (): auto.IInjectorService => singleton;
......@@ -6,7 +6,7 @@ import Drop from 'tether-drop';
// Utils and servies
import { colors } from '@grafana/ui';
import { getTemplateSrv, setBackendSrv, setDataSourceSrv } from '@grafana/runtime';
import { getTemplateSrv, setBackendSrv, setDataSourceSrv, setLegacyAngularInjector } from '@grafana/runtime';
import config from 'app/core/config';
import coreModule from 'app/core/core_module';
import { profiler } from 'app/core/profiler';
......@@ -31,6 +31,7 @@ import { DashboardSrv, setDashboardSrv } from 'app/features/dashboard/services/D
import { ILocationService, ITimeoutService, IRootScopeService, IAngularEvent } from 'angular';
import { AppEvent, AppEvents, locationUtil } from '@grafana/data';
import { backendSrv } from 'app/core/services/backend_srv';
import { auto } from 'angular';
export type GrafanaRootScope = IRootScopeService & AppEventEmitter & AppEventConsumer & { colors: string[] };
......@@ -47,7 +48,8 @@ export class GrafanaCtrl {
datasourceSrv: DatasourceSrv,
keybindingSrv: KeybindingSrv,
dashboardSrv: DashboardSrv,
angularLoader: AngularLoader
angularLoader: AngularLoader,
$injector: auto.IInjectorService
) {
// make angular loader service available to react components
setAngularLoader(angularLoader);
......@@ -57,6 +59,7 @@ export class GrafanaCtrl {
setLinkSrv(linkSrv);
setKeybindingSrv(keybindingSrv);
setDashboardSrv(dashboardSrv);
setLegacyAngularInjector($injector);
locationUtil.initialize({
getConfig: () => config,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment