diff --git a/modules/@angular/platform-browser/index.ts b/modules/@angular/platform-browser/index.ts index 9281511207..310c543355 100644 --- a/modules/@angular/platform-browser/index.ts +++ b/modules/@angular/platform-browser/index.ts @@ -25,7 +25,7 @@ export * from './src/web_workers/shared/message_bus'; export {WORKER_APP_LOCATION_PROVIDERS} from './src/web_workers/worker/location_providers'; export {WORKER_UI_LOCATION_PROVIDERS} from './src/web_workers/ui/location_providers'; +export {NgProbeToken} from './src/dom/debug/ng_probe'; export * from './src/worker_render'; export * from './src/worker_app'; - -export * from './private_export'; +export * from './private_export'; \ No newline at end of file diff --git a/modules/@angular/platform-browser/src/dom/debug/ng_probe.ts b/modules/@angular/platform-browser/src/dom/debug/ng_probe.ts index ffb4ebbf52..949a47412e 100644 --- a/modules/@angular/platform-browser/src/dom/debug/ng_probe.ts +++ b/modules/@angular/platform-browser/src/dom/debug/ng_probe.ts @@ -6,9 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ -import {ApplicationRef, DebugNode, NgZone, RootRenderer, getDebugNode, isDevMode} from '@angular/core'; +import {ApplicationRef, DebugNode, NgZone, Optional, RootRenderer, getDebugNode, isDevMode} from '@angular/core'; import {DebugDomRootRenderer} from '../../../core_private'; +import {StringMapWrapper} from '../../facade/collection'; import {getDOM} from '../dom_adapter'; import {DomRootRenderer} from '../dom_renderer'; @@ -30,24 +31,44 @@ export function inspectNativeElement(element: any /** TODO #9100 */): DebugNode return getDebugNode(element); } -export function _createConditionalRootRenderer(rootRenderer: any /** TODO #9100 */) { +/** + * @experimental + */ +export class NgProbeToken { + constructor(private name: string, private token: any) {} +} + +export function _createConditionalRootRenderer( + rootRenderer: any /** TODO #9100 */, extraTokens: NgProbeToken[]) { if (isDevMode()) { - return _createRootRenderer(rootRenderer); + return _createRootRenderer(rootRenderer, extraTokens); } return rootRenderer; } -function _createRootRenderer(rootRenderer: any /** TODO #9100 */) { +function _createRootRenderer(rootRenderer: any /** TODO #9100 */, extraTokens: NgProbeToken[]) { getDOM().setGlobalVar(INSPECT_GLOBAL_NAME, inspectNativeElement); - getDOM().setGlobalVar(CORE_TOKENS_GLOBAL_NAME, CORE_TOKENS); + getDOM().setGlobalVar( + CORE_TOKENS_GLOBAL_NAME, + StringMapWrapper.merge(CORE_TOKENS, _ngProbeTokensToMap(extraTokens || []))); return new DebugDomRootRenderer(rootRenderer); } +function _ngProbeTokensToMap(tokens: NgProbeToken[]): {[name: string]: any} { + return tokens.reduce((prev: any, t: any) => (prev[t.name] = t.token, prev), {}); +} + /** * Providers which support debugging Angular applications (e.g. via `ng.probe`). */ -export const ELEMENT_PROBE_PROVIDERS: any[] = - [{provide: RootRenderer, useFactory: _createConditionalRootRenderer, deps: [DomRootRenderer]}]; +export const ELEMENT_PROBE_PROVIDERS: any[] = [{ + provide: RootRenderer, + useFactory: _createConditionalRootRenderer, + deps: [DomRootRenderer, [NgProbeToken, new Optional()]] +}]; -export const ELEMENT_PROBE_PROVIDERS_PROD_MODE: any[] = - [{provide: RootRenderer, useFactory: _createRootRenderer, deps: [DomRootRenderer]}]; +export const ELEMENT_PROBE_PROVIDERS_PROD_MODE: any[] = [{ + provide: RootRenderer, + useFactory: _createRootRenderer, + deps: [DomRootRenderer, [NgProbeToken, new Optional()]] +}]; diff --git a/modules/@angular/router/ng_probe_token.ts b/modules/@angular/router/ng_probe_token.ts new file mode 100644 index 0000000000..e99ec23242 --- /dev/null +++ b/modules/@angular/router/ng_probe_token.ts @@ -0,0 +1,16 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {NgProbeToken} from '@angular/platform-browser'; +import {Router} from './src/router'; + +export const ROUTER_NG_PROBE_PROVIDER = { + provide: NgProbeToken, + multi: true, + useValue: new NgProbeToken('router', Router) +}; \ No newline at end of file diff --git a/tools/public_api_guard/platform-browser/index.d.ts b/tools/public_api_guard/platform-browser/index.d.ts index ee8d960cef..d618c355d2 100644 --- a/tools/public_api_guard/platform-browser/index.d.ts +++ b/tools/public_api_guard/platform-browser/index.d.ts @@ -126,6 +126,11 @@ export interface MessageBusSource { initChannel(channel: string, runInZone: boolean): void; } +/** @experimental */ +export declare class NgProbeToken { + constructor(name: string, token: any); +} + /** @experimental */ export declare const platformBrowser: (extraProviders?: any[]) => PlatformRef;