Context with SxcContext
SxcContext describes the Dnn and 2sxc environment of the current Angular application. It includes:
- The global
$2sxcobject - The current module's
sxcinstance - The active application and API editions
- Optional module, content-block, and Angular-path configuration
- Whether the HTTP interceptor should add 2sxc headers
SxcInitializer populates this service from the Angular root element during bootstrap.
Example
Inject SxcContext wherever context information is required:
import { SxcApp, SxcContext } from '@2sic.com/sxc-angular';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
@Injectable({ providedIn: 'any' })
export class TeamService {
readonly team$: Observable<Person[]>;
constructor(app: SxcApp, context: SxcContext) {
const includeGuid = context.sxc?.isEditMode();
this.team$ = app
.query<Person[]>('BusinessUnitTeam')
.getStream('Default', { bu: 'Web', includeGuid });
}
}
In a component template, expose the injected service as a public property:
constructor(public sxcContext: SxcContext) {}
<p>Edition: {{ sxcContext.edition }}</p>
<p>Module: {{ sxcContext.sxc.id }}</p>
Use TypeScript IntelliSense to discover the complete SxcContext API.