MCPcopy Index your code
hub / github.com/angular/angular / PlatformState

Class PlatformState

packages/platform-server/src/platform_state.ts:30–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28 */
29@Injectable()
30export class PlatformState {
31 /* @internal */
32 _enableDomEmulation = enableDomEmulation(inject(Injector));
33
34 constructor(@Inject(DOCUMENT) private _doc: any) {}
35
36 /**
37 * Renders the current state of the platform to string.
38 */
39 renderToString(): string {
40 if (ngDevMode && !this._enableDomEmulation && !window?.document) {
41 throw new RuntimeError(
42 RuntimeErrorCode.DISABLED_DOM_EMULATION_IN_NON_BROWSER,
43 (typeof ngDevMode === 'undefined' || ngDevMode) &&
44 'Disabled DOM emulation should only run in browser environments',
45 );
46 }
47
48 const measuringLabel = 'renderToString';
49 startMeasuring(measuringLabel);
50 const rendered = this._enableDomEmulation
51 ? serializeDocument(this._doc)
52 : // In the case we run/test the platform-server in a browser environment
53 this._doc.documentElement.outerHTML;
54 stopMeasuring(measuringLabel);
55 return rendered;
56 }
57
58 /**
59 * Returns the current DOM state.
60 */
61 getDocument(): any {
62 return this._doc;
63 }
64}
65
66export function enableDomEmulation(injector: Injector): boolean {
67 return injector.get(ENABLE_DOM_EMULATION, true);

Callers

nothing calls this directly

Calls 2

injectFunction · 0.90
enableDomEmulationFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…