Runtime: expose angular injector (#24262)

This commit is contained in:
Ryan McKinley 2020-05-04 14:40:52 -07:00 committed by GitHub
parent 1eb52465d7
commit dd5814b51b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 2 deletions

View File

@ -4,3 +4,4 @@ export * from './dataSourceSrv';
export * from './LocationSrv';
export * from './EchoSrv';
export * from './templateSrv';
export * from './legacyAngularInjector';

View File

@ -0,0 +1,23 @@
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;

View File

@ -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,