Instantiate a ExampleViewer for each example.
(componentName: string, componentClass: Type<ExampleViewer | HeaderLink>)
| 191 | |
| 192 | /** Instantiate a ExampleViewer for each example. */ |
| 193 | private _loadComponents(componentName: string, componentClass: Type<ExampleViewer | HeaderLink>) { |
| 194 | const exampleElements = this._elementRef.nativeElement.querySelectorAll(`[${componentName}]`); |
| 195 | |
| 196 | [...exampleElements].forEach((element: Element) => { |
| 197 | const example = element.getAttribute(componentName); |
| 198 | const region = element.getAttribute('region'); |
| 199 | const file = element.getAttribute('file'); |
| 200 | const portalHost = new DomPortalOutlet(element, this._appRef, this._injector); |
| 201 | const examplePortal = new ComponentPortal(componentClass, this._viewContainerRef); |
| 202 | const exampleViewer = portalHost.attach(examplePortal); |
| 203 | const exampleViewerComponent = exampleViewer.instance; |
| 204 | if (example !== null) { |
| 205 | if (componentClass === ExampleViewer) { |
| 206 | DocViewer._initExampleViewer( |
| 207 | exampleViewerComponent as ExampleViewer, |
| 208 | example, |
| 209 | file, |
| 210 | region, |
| 211 | ); |
| 212 | } else { |
| 213 | (exampleViewerComponent as HeaderLink).example.set(example); |
| 214 | } |
| 215 | } |
| 216 | this._portalHosts.push(portalHost); |
| 217 | }); |
| 218 | } |
| 219 | |
| 220 | private _clearLiveExamples() { |
| 221 | this._portalHosts.forEach(h => h.dispose()); |
no test coverage detected