App providers and SSR APIs
The providers that configure the documentation application, and the APIs for server-side rendering. Add the providers to your application configuration (
Providers
| Provider | Package | Required | Description |
|---|---|---|---|
provideNgDocContext() | @ng-doc/generated | Yes | Provides the generated navigation and site data. |
| @ng-doc/app | Yes | Configures the application. See |
| @ng-doc/app | For search | Provides the search engine ( |
| @ng-doc/app | Yes | Sets the components around the page content ( |
| @ng-doc/app | Yes | Registers the main processors, usually . |
| @ng-doc/app | – | Registers your own processors, after the main ones ( |
| @ng-doc/app | – | Registers a playground control for a type ( |
| @ng-doc/app | – | Registers the component of a playground. Generated code calls it; you don't need to. |
| @ng-doc/app | For diagrams | Enables Mermaid diagrams ( |
The routes of the site are in NG_DOC_ROUTING, also from @ng-doc/generated. The application also needs the Angular router and , because NgDoc registers an HTTP interceptor.
provideNgDocApp
. See also .
| Option | Type | Default | Description |
|---|---|---|---|
contentAnchorScrolling | boolean | false | Scrolls to the anchor in the URL again after NgDoc content has loaded. Use it with the router's anchorScrolling. |
contentScrollPositionRestoration | 'enabled' | 'top' | ' | ' | Restores the scroll position after NgDoc content has loaded. Use the same value as the router's scrollPositionRestoration. |
uiKit | | See below | Paths of the UI kit assets. |
shiki | | – | Extra Shiki themes to load in the browser (themes). theme is deprecated and ignored. |
shortcuts | boolean | true | Whether single-key shortcuts are on for readers who haven't chosen ( |
has two fields. Set both when you pass uiKit:
| Field | Default | Description |
|---|---|---|
assetsPath | 'assets/ng-doc/ui-kit' | Where the UI kit assets are served. |
customIconsPath | 'assets/icons' | Where your own SVG icons are ( |
The site uses the two scrolling options with the matching router options:
provideNgDocApp ({
contentAnchorScrolling: true,
contentScrollPositionRestoration: 'enabled',
});provideSearchEngine
creates the engine class with the given arguments. The default engine is , and its first argument is an object:
| Option | Type | Default | Description |
|---|---|---|---|
stemmer | A stemmer from @orama/stemmers | – | Stems words. Without it, words are not stemmed. |
limit | number | 10 | The most results to return. |
tolerance | number | – | The number of typos to allow. It doesn't work with exact. |
exact | boolean | – | Returns only exact matches. |
The engine returns the matching guides first, then the matching API pages, each in order of relevance. Guides take up to half of limit, or more when fewer API pages match, and API pages fill the rest.
provideSearchEngine (NgDocDefaultSearchEngine , { limit: 20 });To use another engine, extend and pass your class.
providePageSkeleton
. There is no default skeleton: pass for the standard components, or your own object.
| Field | Type | In |
|---|---|---|
breadcrumbs | | |
navigation | | |
toc | | |
Leave a field out to remove that part of the page.
Page processors
registers the processors you pass. Pass for the standard ones, which render links, icons, heading anchors, callouts, tooltips, diagrams, code blocks, demos, demo panes, playgrounds, tabs, images and the members tables of API pages. adds your own, which run after the main processors. Each processor is an :
| Field | Type | Description |
|---|---|---|
component | | The component that replaces the element. |
selector | string | The CSS selector of the elements to replace. |
extractOptions | (element, root) => | Reads the inputs and content from the element. |
nodeToReplace | (element, injector) => Element | Chooses another element to replace. Optional. |
provideTypeControl
registers a playground control for inputs of the given type name.
| Option | Type | Description |
|---|---|---|
hideLabel | boolean | Hides the input name next to the control. |
order | number | The position of the control. The built-in controls use 10 to 40. |
Preload pages
A page's code and content load when the reader opens it. To have them ready before that, set as the router's preloading strategy:
provideRouter (routes, withPreloading (NgDocPreloadingStrategy ));NgDoc then preloads a page when the reader points at, focuses or touches a link to it anywhere on the site: in the sidebar, the previous and next page links, the page content, the search results and the table of contents. After a guide renders, its previous and next guides are preloaded once the browser is idle. Each page is preloaded once, and only the pages the reader is about to open: the strategy never loads every page, as would. Nothing is preloaded on the server, when the reader has turned on data saving, or on a 2G connection. also preloads a page on demand, with preload(url).
Without the strategy, pages still open without a blank page in between: the router keeps the current page on screen until the next page and its content have loaded.
Server-side rendering
| API | Package | Description |
|---|---|---|
| @ng-doc/app | Wraps the server bootstrap function. It waits until NgDoc content has loaded, and fails the render if content failed. |
| @ng-doc/app | The content failures of the current request. reads it. |
| @ng-doc/ui-kit | The base path of the current request: the <base href> or on the server, '' in the browser. NgDoc uses it to request assets. |
Wrap the bootstrap function in main.server.ts:
import { bootstrapApplication , BootstrapContext } from '@angular/platform-browser';
import { withNgDocContentReady } from '@ng-doc/app';
import { App } from './app/app';
import { config } from './app/app.config.server';
const bootstrap = (context: BootstrapContext ) => bootstrapApplication (App, config , context);
export default withNgDocContentReady (bootstrap);Without it, the server can return a page before its content has loaded.